Compare commits

...

200 Commits

Author SHA1 Message Date
hius07 84d28dc5d9
FontList: skip Kindle blacklisted fonts (#11932)
Closes #11927.
14 hours ago
Benoit Pierre ea51435237
bump base (#11941)
Preliminary bump (https://github.com/koreader/koreader-base/pull/1800 will be included in #11930):

- https://github.com/koreader/koreader-base/pull/1790
- https://github.com/koreader/koreader-base/pull/1795
- https://github.com/koreader/koreader-base/pull/1796
- https://github.com/koreader/koreader-base/pull/1797
- https://github.com/koreader/koreader-base/pull/1798
- https://github.com/koreader/koreader-base/pull/1799
- https://github.com/koreader/koreader-base/pull/1801
- https://github.com/koreader/koreader-base/pull/1802
- https://github.com/koreader/koreader-base/pull/1803
- https://github.com/koreader/koreader-base/pull/1804
14 hours ago
SomeGuy 512065fa14
ReaderLink: make AddCurrentLocationToStack always show notification when activated via keypress (#11925)
As seen here https://github.com/koreader/koreader/pull/11900#discussion_r1615474301.
15 hours ago
SomeGuy c429ac8c3f
Menu button support for dictquicklookup, sortwidget, keyboard settings for NT (#11933)
Menu key support for some widgets. would have closed #11783 and #6463 (cumulative with @comphilip's fixes)

It fixes a problem where some virtual keys were not available for non-touch users. closes #11862

Also, adds keyboard settings to non-touch devices. closes #11934
16 hours ago
Benoit Pierre 2f0e456a42 ci/macos: dump binaries runtime path & dependencies
Useful information for investigating issues with the bundle.
2 days ago
Benoit Pierre b7c1957e4b macos: fix bundle
The new build system should normally be free from "brew infections",
and already have the proper runtime path and library names.
2 days ago
Benoit Pierre 4750b4a4cd ci/macos: drop unnecessary build dependencies 3 days ago
Benoit Pierre 404c7c0dfe ci: update build directory trimming before caching 3 days ago
Benoit Pierre 5a465f413b tweaks for new build system
- forward unknown make targets to base
- add `cmake` and `staging` directories to ignored output artifacts
- drop `package.path` and `package.cpath` luarocks specific entries
3 days ago
Benoit Pierre 1c9c35dcb3 bump base 3 days ago
nairyo c7a59145a3
[fix] VocabBuilder: restore erroneously removed onShowVocabBuilder function (#11915)
Fixes #11913.
5 days ago
Piotrek Marciniak 9b1a21ef82
Export highlights: empty annotations as nil instead of empty string (#11912)
Fixes Readwise exports
5 days ago
SomeGuy 1aefd80ea6
ReaderBookmark: "bookmark current page" removed from NT kindles (#11907)
Discussed https://github.com/koreader/koreader/issues/11834#issuecomment-2132411929 onwards.
5 days ago
Frans de Jonge 94372c2adf
Remove ShowFontMenu (#11904)
Some clean up, as suggested in <https://github.com/koreader/koreader/pull/11864#discussion_r1615312993>.
5 days ago
SomeGuy eb63cf655f
CoverBrowser: update MosaicMenu FocusManager grid view to 2D (#11906)
This PR [and #11884] are for #11834.
5 days ago
Frans de Jonge ffc43030ec
ReaderLink: change (hasScreenKB or hasSymKey) add to notification stack shortcut to Press instead of Down (#11905)
See 316c6a0624 (r1615314584)
5 days ago
hius07 9223cde2bd
Status bar: fix book progress (#11885) 5 days ago
Frans de Jonge 8f2bd5420d
Introduce Device:useDPadAsActionKeys() (#11900)
1. Non-Kindle-specific `hasFiveWay` behavior is changed to `hasDPad and useDPadAsActionKeys`. For now they remain Kindle-specific in practice, unless one sets `useDPadAsActionKeys = yes` in a user patch.
2. With that disambiguation out of the way, `hasFiveWay` itself is further disambiguated into `hasScreenKB` and `hasSymKey`, as per the actual property being used, rather than something that tends to correlate with it. (It needn't be Kindle-specific per se, but non-Kindle devices have equivalent shortcuts with for example `Shift`.)
  Running the emulator with `DISABLE_TOUCH=1` will set `hasSymKey = yes`, which can be tested with right shift.

Closes #11887.
6 days ago
Martín Fernández 3fb2f18041
update tool to generate metadata translations (#11869)
* updated:

    - strings to translate
    - english metadata

* added:

    - appstream: metadata generator
    - appstream: translation of screenshot captions, if they're present.
    - appstream: link to gh release notes
6 days ago
Frans de Jonge a21db40745
[i18n] ReaderBookmark: don't bother translators with a space (#11902) 6 days ago
SomeGuy 00d0affd70
Remove very long press settings from NT (#11898) 6 days ago
SomeGuy d217f5c161
Menu widget: limit right as hold to hasFewKeys (#11890)
Addresses concerns in #11884.
6 days ago
hius07 076f77282b
FileManager copy/move: do not paste to itself (#11878) 6 days ago
hius07 c6e6d72cf3
Collections: add collection mark to books (#11868) 6 days ago
ziz57 7925455b68
Add ReaderLink::registerScheme for plugins handling non-http(s) links (#11889)
Currently, links with a scheme other than http or https are rejected. But plugins may want to handle them. This allows them to, by registering the scheme with self.ui.link:registerScheme("example") during the plugin's init.
7 days ago
Frans de Jonge b222900cb9
Enable Alt+Shift+G for screenshots on all devices with a keyboard (#11888) 7 days ago
hius07 556e5bd6b4
VirtualKeyboard: delete word on backspace swipe west (#11843)
Closes #11831.
7 days ago
SomeGuy 81575ae24f
Global long press on K4, 'ScreenKB' + 'Press' (this time for real) (#11884)
discussed #11834

then merged #11872, then reverted #11881
1 week ago
NiLuJe f0f37e3153
Kobo: Boost saturation for CFA refreshes (and add a dev setting to disable it) (#11883)
Being able to disable it can be interesting, because it *is* a somewhat destructive process.

* Requires a base bump:
https://github.com/koreader/koreader-base/pull/1793
https://github.com/koreader/koreader-base/pull/1794
1 week ago
Frans de Jonge 07b507370f
Revert "Global long press on K4, 'ScreenKB' + 'Press' (#11872)" (#11881)
This reverts commit 3f64ecfd28.
1 week ago
poire-z fd7e224c16 userpatch: add a few helpers that can be used in userpatches
Make the few tricks we discovered readily available,
which should make user patches simpler.
1 week ago
poire-z f00a88aef7 AltStatusBar: show page info similar as in footer
We now build the "page/total %" string ourselves,
with the same logic as used in the footer (including
when hidden flows or reference page numbers are used)
and give it to crengine to be displayed instead of
its own way of doing it.
1 week ago
poire-z 54a0cdd737 ReaderFooter: fix minor issues with pages left & chapter progress
When using Reference page numbers, "Pages left" was showing the
same info as "Current page", because Reference pages, being strings,
couldn't be used for arithmetics. But we can just count the number
of items left in the Reference pages array of strings.

Also fix edge case with "page progress" with hidden flow when
we are before the first chapter with a hidden flow before.
1 week ago
Frans de Jonge 20d8a5c313
FocusManager: enable more keyboard shortcuts by default (#11871) 1 week ago
SomeGuy 3f64ecfd28
Global long press on K4, 'ScreenKB' + 'Press' (#11872)
discussed #11834
2 weeks ago
Frans de Jonge 5b18c30336
Quickstart guide: set dir="rtl" when we're in an RTL language (#11867)
Reported by @Monirzadeh in <https://github.com/koreader/koreader/issues/11147#issuecomment-2122164344>.
2 weeks ago
SomeGuy e859109885
Status bar: major UI makeover (#11678) 2 weeks ago
poire-z 40814bf12b
bump crengine: minor fixes (ruby, a crash, non-linear flows) (#11863)
Includes:
- html5.css: really ensure ruby centering
- getRenderedWidths(): fix possible crash with 0-width images
- Page splitting: ignore empty non-linear flows
- LvDocView header: allow overriding "page/total %"
CreDocument: add setPageInfoOverride() to allow tweaking
top status bar display of page number/count/% (to be
implemented in a later commit).
2 weeks ago
SomeGuy 6c7e2a9c62
Support screenshots on Non-Touch with ScreenKB as modifier (#11802)
on devices (mostly kindles) with keyboards: Alt + Shift + G
on kindle 4: ScreenKB + Menu
2 weeks ago
SomeGuy 577c5d454f
Non-touch DPad improvements (#11749)
Closes #11295.
2 weeks ago
Martín Fernández 36d2e3cf74
Add README.md to Linux package (#11859) 2 weeks ago
yparitcher 59fb906921
NetworkListener: fix FM integration & properly gate behind hasWifiToggle (#11858) 2 weeks ago
NiLuJe 4d9c6523ad
Input: Some more followups to the input device auto-detection stuff (#11855)
Switch to a new `input.fdopen` API & wrapper so we can keep the fds opened by `fbink_input_scan` instead of closing them to re-open them right after that...

This should hopefully help on racy zForce devices that attempt to handle power management when opening/closing the device. We know this sometimes horribly fail to re-activate the IR grid (c.f., our manual activation on resume), but this apparently could also happen here (re: #11844) because of the quick succession of open->close->open.
2 weeks ago
Martín Fernández 1eb2095ead
Desktop: add all supported mimetypes. (#11847)
Change the comment to "ebook reader"
2 weeks ago
Martín Fernández 89a6ae28a6
appstream: update metadata (#11851)
proper requires, supports and recommends
all supported mimetypes
add branding colors
2 weeks ago
Martín Fernández 635d243152
debian: update metadata (#11854)
Slightly modified to avoid: E: koreader: description-starts-with-package-name
2 weeks ago
Nico Hirsch 3b97e2988a
Shorten home folder path for info messages (#11853)
The info messages for opening files always show the full path. By using `filemanagerutil.abbreviate`, the info messages now show the shortened home folder path (only if the setting "shorten home folder" is enabled).
2 weeks ago
Martín Fernández ba8891082c
fix after #11833 (#11849) 2 weeks ago
Tomáš Janoušek e94550a261
PocketBook: Open links in the on-device web browser (#11787)
Many PocketBook devices include a web browser, but when clicking a link in KOReader, there was no option to open the link in the browser, there was only an option to show a QR code (which can then be scanned by a smartphone).

This commit implements `canOpenLink`/`openLink` on PocketBook using the "browser.app", if available.

Tested on PB740 (InkPad 3).

Fixes: https://github.com/koreader/koreader/issues/11782
Related: https://github.com/koreader/koreader/issues/6597
2 weeks ago
Martín Fernández 7bded465eb
SDL: add flatpak flavor (#11833)
* ship metadata with generic linux binaries
* append release version & data at build time
2 weeks ago
Martín Fernández d801af6d41
bump metadata translations (#11842)
updating metadata for 50 languages
short_description.txt: 8 new | 18 updated | 24 not translated
full_description.txt: 10 new | 15 updated | 25 not translated
2 weeks ago
hius07 daf0fa4b4b
MultiInputDialog: fix keyboard height changed (#11832) 2 weeks ago
hius07 6b192c346a
Annotations: Bookmark list improvement (#11825) 2 weeks ago
hius07 46449eb06e
Page overlap: add dashed line marker (#11804)
Requested by our contributor in #11734 (comment).
2 weeks ago
nairyo 126c01e1b5
Replace tweak_buttons_func with an event instead (#11777)
Also see https://github.com/Ajatt-Tools/anki.koplugin/issues/22
2 weeks ago
hius07 db63db11b2
FileManager: safe initial path (#11774)
We do not like trailing slash in the path (except root).
Closes #11772.
2 weeks ago
NiLuJe 05168b22f5
Kindle: Don't forget about fiveways on legacy devices & fix a couple input-scan misdetections (#11827)
* Kindle: Don't forget to open INPU_DPAD devices for the fiveways. Somehow managed to skip my mind, they're often on a separate input device.

Regression since #11807

* Update FBInk to fix a few cases of input_scan misdetection (on misconfigured drivers (e.g., no DIRECT prop on supported kernels), or old kernels with no EVIOCGPROP support).

Fix #11824
2 weeks ago
Philip Chan 5d63907cae
fix #11810: only set FocusManager layout if hasDPod (#11811) 2 weeks ago
NiLuJe fd5260f2ce
Support auto-detection of input devices via fbink_input (#11807)
* Kobo: Drop a bunch of if ladder crap and switch to auto-detection of input devices via fbink_input
* Kindle: Drop an even larger bundle of crap to do the same ;p. (re: #11392)
* ExternalKeyboard: Switch to fbink_input to whitelist keyboards instead of the manual parsing of caps via its FindKeyboard class
* Input: Extended open/close wrappers to handle logging & tracking of dupe open/close calls.
2 weeks ago
Martín Fernández 79be8a10b1
appimage: keep metadata in sync with flathub (#11819)
Because it is actually pulled from here :p
3 weeks ago
Benoit Pierre a9a023c062
doc: fix android NDK / SDK instructions (#11818) 3 weeks ago
Benoit Pierre ea538900ba ci/macos: install ninja 3 weeks ago
Benoit Pierre b2d495fcdd ci: force color output 3 weeks ago
Benoit Pierre 0aaa8e7c5b ci/macos: drop unnecessary permissions stanza 3 weeks ago
Benoit Pierre f82cc31717 ci/macos: add caching to speedup workflow 3 weeks ago
Benoit Pierre a12b075e07 ci/macos: avoid concurrent workflow runs on the same ref 3 weeks ago
Benoit Pierre b28c58b902 ci/circle: tweak resource classes 3 weeks ago
Benoit Pierre 76bdb7e65c ci/circle: improve caching
Don't cache the whole base directory; instead independently cache:
- the build output directory
- the ccache directory

This allow completely avoiding the need for building base if a
cache (keyed on the relevant parts of the git tree for base) is
successfully restored, as well as reducing the amount of cached
data.

Additionally, ensure caches are isolated by branch name (but allow
falling back to a "master" cache for restore): we don't want PRs
using each others' caches.
3 weeks ago
mergen3107 8a316f928a
Kindle: remove separate L and R orientations (#11780)
Fixes #11743
3 weeks ago
Benoit Pierre 25d29aca4a
android: fix building with kodev (#11817)
If the Android NDK and/or SDK are not setup, `kodev` will try to invoke
the `android-ndk` and/or `android-sdk` make targets.  This can't be done
with `TARGET=android`, as `base/Makefile.defs` will error out trying to
call the (missing) compiler to get the target machine. Those rules need
to be available to all targets.
3 weeks ago
Benoit Pierre c9c8089188
bump base (#11814)
- https://github.com/koreader/koreader-base/pull/1782
- https://github.com/koreader/koreader-base/pull/1783
- https://github.com/koreader/koreader-base/pull/1784
3 weeks ago
Martín Fernández 2c6808ba78
Add generic Linux package (#9351)
Relates to https://github.com/koreader/koreader/issues/9268
Requires https://github.com/koreader/koreader-base/pull/1504

Usage: 
- `kodev release linux` for native package (same arch as host)
- `LINUX_ARCH=arm release linux` for armhf on a x86_64 host.
- `LINUX_ARCH=arm64 release linux` for arm64 on a x86_64 host.

It produces a `koreader-linux-$ARCH-$VERSION.tar.xz` archive, where $ARCH follows `uname -m` convention {x86_64, armv7l, aarch64}

To generate the debian package from the generic archive the following command is required

`./platform/linux/do_debian_package.sh path_to.tar.xz`
3 weeks ago
sdasda7777 eb7af994e1
Check if /usr/bin symlink is present to fix instance reuse issue on older Pocketbooks (#11764)
Fixes #11760.
3 weeks ago
Nico Hirsch 3e04184638
calibre: add wireless connectionstart/stop actions (#11806)
* Register start stop connection actions

* Match code order

* Title to lowercase
3 weeks ago
Philip Chan f0a3bcf05b
NT: add Hot swapping dictionaries button and edit button into FocusManager's layout (#11803)
fix #11783
3 weeks ago
Benoit Pierre 7ba42579eb bump base 3 weeks ago
Benoit Pierre 8c0362f9ed make: ignore thirdparty directory when installing 3 weeks ago
Benoit Pierre 5a146414db make: symlink fonts / plugins on install 3 weeks ago
Benoit Pierre 49e3251e7b make: support changing the build / install directory location 3 weeks ago
Benoit Pierre f749fc2fd9 make: move target specific rules to dedicated files 3 weeks ago
Benoit Pierre 417d56b440 make: small improvement
Avoid duplicate `make -C base` call when building from scratch, as well
as support avoiding the remaining call (using `make --assume-old=base`).
3 weeks ago
Benoit Pierre a4526633dd make: reduce the number of `$(shell …)` calls
Through use of `$(INSTALL_DIR)`.
3 weeks ago
Benoit Pierre 5efba26d80 make: ensure `base/Makefile.defs` can be included
Automatically run `fetchthirdparty`.
3 weeks ago
Benoit Pierre 3f8f87d294 make: minor cleanup 3 weeks ago
Benoit Pierre a4400b3ccb tools/mk7z: support debian unstable / ubuntu 22.04
The version of `7z` provided by `p7zip-full` is now the same as `7zip`:

- symlinks are dereferenced by default (no support for `-l`)
- `7z -ba h` appends a trailing `/` to directories
  (not present in the output of `7z -slt l`)
3 weeks ago
Benoit Pierre 2d4b12c99c tools/mk7z: tweak manifest handling code
To support mawk (default awk on debian unstable).
3 weeks ago
Benoit Pierre e921ed1bc7 tools/mk7z: fix subtle bug in manifest handling
A string like `1E2` is interpreted as `100` (`1×10²`):

```bash
▹ echo 0E036904 | awk '{ if ($1) print $1 }'
▹ echo 0E036904 | awk '{ if ($1!="") print $1 }'
0E036904
```
3 weeks ago
SomeGuy baab326332
[ReaderHighlight] Remove duplicated setting on NT devices (#11750)
Closes #11747.
3 weeks ago
Joshua Bullock 1398154546
Gesture: Add toggle for orientation lock (#11795) 3 weeks ago
Predrag Đokić eb6e5e3c20
Kindle: Fix missing Amazon UI screensaver after exiting KOreader (#11794) 3 weeks ago
hius07 12c3c190b0
Annotations: fixes 2 (#11788)
* readerbookmark: fix index for reverse sorting

* readerhighlight: fix pdf tap on highlight detection
3 weeks ago
Benoit Pierre 075edf9980 tests/readerhighlight: speedup
Reduce time to run those tests by 74% on my machine (~8.8s → ~2.3s).
3 weeks ago
Benoit Pierre 554e8daf99 tests/readerhighlight: avoid changing versioned files
Work on a copy of `test/sample.pdf`.
3 weeks ago
Benoit Pierre 089c19cb39 tests/readerbookmark: avoid changing versioned files
Work on a copy of `test/sample.pdf`.
3 weeks ago
Benoit Pierre 3e809b6c7b tests/readerlink: speedup
Reduce time to run those tests by 95% on my machine (~17s → 0.8s).
3 weeks ago
Benoit Pierre fdf19e98c3 tests/readerlink: factorize setup/teardown code 3 weeks ago
Benoit Pierre d0ca04c48d tests/readerlink: reorganize
Group tests by file type (EPUB or PDF).
3 weeks ago
Benoit Pierre b67c6147d5 tests: ensure successive testsuite runs work
Don't carry over some old settings. Additionally, avoid clobbering the standard reader settings.
3 weeks ago
peicuiping a7e34673e6
chore: remove repetitive words (#11785) 3 weeks ago
Valentin Dubois 526a1fb727
Initial support for new Kobo (Clara B/W + Colour, Libra Colour) (#11737)
* Support the Clara B&W, Clara Colour & Libra Colour
* Enable HW dithering on *all* the Kobo MTK devices
* Enforce 32bpp instead of 8bpp for Kobo devices with a color panel (the driver doesn't actually support 8bpp anyway)
* Enable standby support on MTK (whenever possible, i.e., not when plugged in, as that is horribly, horribly broken).
* Enforce the dedicated "color" waveform mode for image content in ScreenSaver, ImageViewer & Reader.
* Fix charging LED support on MTK
* Tweak the frontlight ramp on MTK + LM3630 so that it actually ramps smoothly
3 weeks ago
Benoit Pierre 821120828b
tests: fix EPUB test (#11776)
The `droid sans fallback` test incorrectly assumes `Droid Sans Mono`
will be the first font in the list of fallback fonts, but the list
is alphabetically sorted.

Cf. https://github.com/koreader/koreader/pull/10566
3 weeks ago
sdasda7777 8530282d38
Add Czech keyboard layout (#11769)
Fixes #11339.
3 weeks ago
hius07 725df17c45
Annotations: fixes (#11761) 4 weeks ago
hius07 c47d3b3177
Menu widget: cleanup (#11759) 4 weeks ago
zwim bf58723af1
[CoverImage] Honor rotation after opening of a book (#11752)
If rotation changes, create a new cache entry and use that if necessary.

Fixes #11713.
4 weeks ago
SomeGuy e51b71f463
[Gestures.plugin] Clarify some rotation gesture strings (#11753) 4 weeks ago
poire-z 001e90db1e ReaderSearch: delay adding to location stack until we change page
Search may highlight matches on the current page, and if there
are no others in the book, we would stay there and resume reading;
but we would get a spurious previous location (ie. in Book map)
that we would not expect keeping, and we may accidently go back
to previous location, losing our reading position.
Avoid this by only adding current page to location stack when
actually leaving the current page.
Because of complications with other reading modes, this is
currently only enabled for CRE document when in page mode.
4 weeks ago
poire-z 03d16270d9 Statistics: handle correctly page change when reading paused
As currently we only handle ReadingPaused/Resumed on suspend
and resume, no page change should happen while paused, so
there is no current issue to fix. But let's get ready for
other use cases (which may be brought in by user patches,
ie. pausing while the SkimWidget is displayed, and obviously
triggers page changes).
4 weeks ago
poire-z 7d94562602 ReaderToc: fix issues when on a page before first Toc Item
When on a page before the first ToC item (the first chapter),
that first chapter title may be shown in the footer instead
of a more correct blank title.
This bug might still have had other small effect elsewhere.
4 weeks ago
poire-z ca90b982b4 ReaderStyleTweak: reword CSS suggestions info text 4 weeks ago
poire-z 1c9a6509a2 HttpInspector: allow browsing global variables 4 weeks ago
Benoit Pierre 89b1280166
bump base (#11748)
- https://github.com/koreader/koreader-base/pull/1773
- https://github.com/koreader/koreader-base/pull/1775
- https://github.com/koreader/koreader-base/pull/1776
- https://github.com/koreader/koreader-base/pull/1777
- https://github.com/koreader/koreader-base/pull/1778
4 weeks ago
hius07 d82815952e
Annotations, part 1 (#11563)
New format to handle annotations (page bookmarks, highlights, notes) and store them in the book metadata files.
4 weeks ago
hius07 6b0d97bf22
Multiple collections (#11693) 1 month ago
Benoit Pierre 087ddd1510 ci: small macOS cleanups
Reduce differences with the configuration used on koreader-base.
1 month ago
Benoit Pierre 7392dd2ad4 ci: tweak macOS CI checkout phase
Use the same parameters as for the koreader-base job (faster).
1 month ago
Benoit Pierre 54ded2c578 ci: fix macOS build
Work around the fact that the lua@5.1 brew formula has been disabled.

Additionally, drop ragel (no necessary anymore).
1 month ago
Benoit Pierre ad6e3b34c4 bump luajit-launcher 1 month ago
Benoit Pierre 64213bf3d9 bump base 1 month ago
Benoit Pierre 6d5ad05e9f ci: bump docker images 1 month ago
hius07 8ff846ba6e
SortWidget: sort alphabetically (#11705) 1 month ago
Benoit Pierre e8544316a8
pocketbook: simplify device model detection (#11721)
To avoid avoid having to manually handle the multiple
ways a model name reported by inkview can be formatted.
1 month ago
vyaus f793c6a36c
Gesture: add jump to random page (#11727) 1 month ago
Frans de Jonge 34abb4e22b
Update translations for v2024.04 (#11726) 1 month ago
Galunid ca14420372
Add relevant nil guards to prevent reflow crashes (#11715)
closes #10854 #9272 #4481
1 month ago
hius07 f5be04a738
Keyboard: detect tap if swipes are disabled (#11699)
Discussed in #11668.
1 month ago
mergen3107 caea0e8fb2
Kindle Scribe: improve gyro detection, replace accel with acc keyword (#11696)
Fixes #11691.
1 month ago
ElimGarak1 bfc84795c8
Add PocketBook Era Color (PB700K3) (#11695)
Fixes #11684.
1 month ago
Max Ignatenko 87c85bf94d
NewsDownloader: use <content:encoded> from RSS item, if available (#11694)
This makes it work much nicer for feeds that provide the full content in the feed itself.
1 month ago
SomeGuy c70c9f0905
Hide hidden flows and custom toc from non-touch devices (#11690) 1 month ago
mergen3107 d3011571a3
Kindle Scribe: find accelerometer based on hardware (#11642)
Closes #11392 (temporarily).
1 month ago
Max Ignatenko b872191dc9
Stop touching night mode when control_nightmode == false (#11685)
This is a regression introduced in #10762
1 month ago
Benoit Pierre 715f5aa747 ci: cleanup CircleCI fetch phases 2 months ago
Benoit Pierre 8b8258b44a make: speedup `fetchthirdparty`
- shallow clone submodules configured as such
- on CI, shallow clone all submodules
- use 3 jobs
2 months ago
Benoit Pierre f3dcc70d8d l10n: mark git submodule for shallow updates 2 months ago
Benoit Pierre 4a343d3669 ci: bump CircleCI docker images 2 months ago
Benoit Pierre 21c6e37f5e ci: remove CircleCI unnecessary steps
The docker images should already contain all the necessary tools.
2 months ago
Benoit Pierre c345de5d71
ci: drop travis configuration (unused) (#11676) 2 months ago
Benoit Pierre ad6607cb4c
make: improve `appimageupdate` rule, take 2 (#11671)
The FUSE detection is false positive under Gitlab's pipeline,
so just use the hidden `--appimage-extract-and-run` option to
automatically and always "extract & run" the appimage tool.
2 months ago
Frans de Jonge f93cc6e916
[AppImage] AppImageTool 13 (#5275) (#11665)
https://github.com/AppImage/AppImageKit/releases/tag/13
2 months ago
Benoit Pierre 8b4b3025eb
make: improve `appimageupdate` rule (#11669)
Instead of trying to detect if running under Docker, use a simpler
wildcard check to detect if FUSE support is available. This as the
advantage of supporting Docker, rootless Docker, and Podman.
2 months ago
Benoit Pierre 0dbfac22b0
make: fix `appimageupdate` rule (#11662)
Update sdnio library soversion to account for new docker image based on Ubuntu 20.04.
2 months ago
Benoit Pierre 12552f1c71
doc: remove ragel from the build requirements (#11661)
Not necessary anymore.
2 months ago
Benoit Pierre c503e9e848
make: fix test rule (#11659)
Use the same code as in base (Cf. https://github.com/koreader/koreader-base/pull/1756).
2 months ago
poire-z d178273671
bump base, luajit-launcher, avoid assert failure in sub-processes (#11658)
Bump base:
- Update LuaJIT to 20240310
- harfbuzz: fix ccache 4.9.1 errors
- ci: drop unnecessary macOS build dependency
- CRE: avoid assert failure in sub-processes
Bump luajit-launcher:
- Update LuaJIT to 20240310
Frontend:
- CreDocument: prevent assert failure in sub-processes
2 months ago
Frans de Jonge 31c28378e7
[i18n] GetText: fix fuzzy detection for certain strings (#11648)
Reported in <https://github.com/koreader/koreader/pull/11647#issue-2233008767>.

Probably overlooked in #5807
2 months ago
SomeGuy fb86acaf1a
Sleep screen wording fixes (#11647) 2 months ago
Frans de Jonge ad266f46c2
GetText: fix crash if a value is used as unique value and as singular/plural (#11643)
Concretely 1 second, %1 seconds since #11549 added `1 second` all by itself.
2 months ago
SomeGuy 279f16aa23
Sleep screen menu reworked (#11549) 2 months ago
Bastian Wagner aaa56a814f
CreDocument: support added 'identifier' metadata (#11628)
Currently not exposed in Book information.
2 months ago
poire-z ac4d4756f8
bump crengine: various fixes, updated russian hyphenation (#11637)
Includes:
- Russian hyphenation: allow hyphens after Russian "не" prefix
- EPUB: add "identifiers" to doc props
- EPUB: avoid crash when '@font-face' in <head><style>
- FB2: fix block images sizing and centering
- lvrend: fix positioning of bottom border on empty block elements
Also includes:
- cre: add 'identifiers' to doc props
- build and ci: various tweaks
2 months ago
Tomas Janousek 1fbdc1f19d NetworkMgr: Limit the hasDefaultRoute check in isOnline to PocketBooks
It's not necessary on other platforms. To be more precise, it would be
necessary on Kobo as well, but there's a different workaround in place:
https://github.com/koreader/koreader/pull/6424/files#diff-be863601c59a2d6607af6b04b3be2392ec4494df6d25dae48250fae57b737f61R216-R224
2 months ago
Tomas Janousek 4fa6783dbb NetworkMgr: Use cheaper/simpler hasDefaultRoute in isOnline
Device:getDefaultRoute parses /proc/net/route and converts the hex
addresses to textual IP addresses, but in `isOnline` we don't care what
address the gateway actually has, we only care about whether we have a
default route into the Internet.

This provides a simpler alternative that does the equivalent of
"ip route get 203.0.113.1 || ip route get 2001:db8::1" (note that it
does support IPv6-only connectivity as opposed to
Device:getDefaultRoute) and returns true if we have a route.

Inspired by https://github.com/pavel-odintsov/get_default_outgoing_ip_linux
2 months ago
Tomas Janousek b3e125a7ce NetworkMgr: Fix PocketBook losing net access
Doing the `isOnline` check (`socket.dns.toip("dns.msftncsi.com")`)
without having internet connectivity (`!isConnected`) results in the
`isOnline` check never succeeding again even if connectivity is later
acquired. This is most likely caused by /etc/resolv.conf only being
parsed once - https://sourceware.org/bugzilla/show_bug.cgi?id=984, an
issue that was fixed in glibc 2.26 (PocketBook firmware U740.6.8.2461
has glibc 2.23).

This fix works around the problem by checking if we have a default route
first before even attempting to check `isOnline`. If we don't, then
`isOnline` is (almost) guaranteed to fail anyway.

We could alternatively check `isConnected` instead, but that only checks
wireless connectivity on many platforms, and we could have internet
access via USBNet instead. Checking for the default route via any
interface should work reliably for both wireless and USBNet
connectivity.

Another alternative fix is to add a fallback nameserver to
/etc/resolv.conf like we do for the Kobo platform [1]. Unfortunately,
this fix would not work in the following (rather common) scenario:

1. PocketBook boots, connects to WiFi
2. KOReader starts, /etc/resolv.conf looks all right, no fallback needed
3. PocketBook goes to sleep, disconnects from WiFi, clears resolv.conf
4. PocketBook wakes up, stays disconnected
5. KOReader user does a Wikipedia lookup, networking freezes

[1]: https://github.com/koreader/koreader/pull/6424/files#diff-be863601c59a2d6607af6b04b3be2392ec4494df6d25dae48250fae57b737f61R216-R224

Fixes: https://github.com/koreader/koreader/issues/10183
Related: https://github.com/koreader/koreader/issues/6421
2 months ago
hugleo cd7d3b5ef6
Bump luajit-launcher (#11636)
Add support for C64P
2 months ago
Denis Malinovsky 6cc970dbb4
Do `flashui` refresh for first display of History page (#11603)
This fixes ghosting for color Pocketbook devices

Fixes #11602.
2 months ago
hius07 c415aea67e
File manager: fix classic mode item font size (#11626)
Closes #11625.
2 months ago
Frans de Jonge 601925ab87
[minor] CSS tweaks: fix typo cellpading → celpadding (#11618) 2 months ago
Frans de Jonge ec54afcc0d
[minor] ReaderStyletweak: fix typo (#11616) 2 months ago
Frans de Jonge a7edf213a5
[minor] FileChooser: use en-dash instead of dash for UI (#11615) 2 months ago
SomeGuy f6588e95e8
ReaderHighlight: ~~strikeout~~ → Strikethrough (#11619) 2 months ago
Frans de Jonge b1a80921ad
Revert "ReaderPaging: enable Kindle page-turn animations (#11424)" (#11617)
This reverts commit ee7c3ab551.
2 months ago
Frans de Jonge b9261e0245
[i18n] Font UI fallbacks: insert replacement characters with template for Weblate compatibility (#11614)
Added in <https://github.com/koreader/koreader/pull/8722> and unproblematic for the past two years, but Weblate has now decided to complain about it to the extent of disabling translations:

> Error message
String contains control character: 'If some book titles, dictionary entries and such are not displayed well but shown as \ufffe\ufffe or ��, it may be necessary to download the required fonts for those languages. They can then be enabled as additional UI fallback fonts.\nFonts for many languages can be downloaded at:\n\nhttps://fonts.google.com/noto\n\nOnly fonts named "Noto Sans xyz" or "Noto Sans xyz UI" (regular, not bold nor italic, not Serif) will be available in this menu. However, bold fonts will be used if their corresponding regular fonts exist.'
2 months ago
Benoit Pierre dce92020c1
bump base: fix sdcv binaries on non-Android/macOS platforms (#11609)
Closes #11604.
2 months ago
hasezoey 42c93a7623
FileChooser collates: use "item.sort_percent" for sorting + extra `on-hold` handling (#11592)
re https://github.com/koreader/koreader/pull/11524#issuecomment-1984110990
re https://github.com/koreader/koreader/pull/11542#issuecomment-2018164346

re #11592
2 months ago
SomeGuy fbd3e822fe
ReaderView: increase underline thickness (#11586)
Closes #11581.
2 months ago
Denis Malinovsky 501cba6ebe
PocketBook: remove unused `color_saturation` parameter (#11597)
Bumps base for https://github.com/koreader/koreader-base/pull/1751

Includes several build system improvements as well
2 months ago
dkabot ee7c3ab551
ReaderPaging: enable Kindle page-turn animations (#11424)
Fixes #11423.
2 months ago
Frans de Jonge ca8e9352ba
[i18n] Add en-GB and Romanian translation to UI (#11577)
* Add en_GB translation to UI

Follow-up to https://github.com/koreader/koreader-translations/pull/167

* Uncomment Romanian
2 months ago
Denis Malinovsky f4a8514545
ReaderTypography: update menu features symbols for Russian (#11570) 2 months ago
poire-z 86cb5cbd4c
bump crengine: various fixes, improved Russian typography (#11578)
Includes:
- In-page footnotes: avoid with '-cr-hint: noteref-ignore'
- In-page footnotes: ensure they don't cross "flows"
- Tables: fix rendering when negative text-indent
- FB2 cover drawing: ensure _invertImages flag
- EPUB: fallback to look for a cover in the first fragment
- TextLang: Russian: add typography rules
Also update to libunibreak 6.1.
2 months ago
poire-z 67cd647d1a
ReaderToc: add option to show chapter lengths (#11546) 2 months ago
hius07 c8c4e0301a
covermenu: fix file dialog (#11576) 2 months ago
Frans de Jonge 9387fcd2d0
[fix] ReaderLink: fix copy link (#11569)
Fixes #11567.
2 months ago
hius07 bb98cbf612
ReaderStatus: update status modification time (#11568)
In the "End of the book" action.
Closes #11564 (No idea how we got a book without modification time but the time stamp must be updated in any case)
2 months ago
hugleo 424fa9b6fd
ReaderView: ensure that the pan zoom direction is not nil (#11557)
Fix gif and web files not opening: https://github.com/koreader/koreader/pull/11425#issuecomment-2002164851
3 months ago
Martín Fernández 5d2782ddfe
bump luajit-launcher (#11554)
Add Linfiny eNote / Avalue ENT-13T1 / QuirkLogic Papyr
3 months ago
Martín Fernández 3638adc841
appimage: get full path before changing to assets dir (#11552) 3 months ago
Jo Van Bulck 4d19ce24ed
Dictionary: Fix download message when connection fails (#11548) 3 months ago
hugleo 95ce974ef9
bump base/libk2pdfopt and luajit-launcher (#11540)
- libk2pdfopt: allow asymmetric margins for auto-crop.
- luajit-launcher: new devices for e-ink test
3 months ago
poire-z 9a84755e56
Wikipedia EPUBs: add settings for include/highres images (#11544)
Allows setting a default answer to the "Include image"
and "slightly higher quality images" questions when
saving a Wikipedia article as EPUB.
3 months ago
poire-z 191ef2b4c0
Book style tweak: add more suggestions in "CSS ≡" (#11533) 3 months ago
hugleo b026f84949
ReaderZooming: make auto-crop default be page content (#11438) 3 months ago
SomeGuy ac0483bfce
Screensaver: 0% only on first page, 100% only on final page (#11541)
Fixes #11516
3 months ago
Frans de Jonge 20813cab53
Wallabag: properly deal with mimetype actually being content-type (#11532)
A typo snuck in #11492, which should've read `not type(article.mimetype) == "string" or type(article.mimetype) == "string" and not article.mimetype:find("^text/html")`. But in most cases the behavior would've been identically broken because of the same underlying issue: Wallabag mimetype is actually HTTP content-type.

Fixes #11528.

Also introduces a new setting associated with the behavior in case people have different preferences.
3 months ago
hius07 5414858b74
Menu widget: fix item property name (#11534) 3 months ago
poire-z 0eaa2d8248 Wikipedia: tweak EPUB css to force epub.css look
Include in the EPUB stylesheet most of our epub.css
tweaks, so we get our expected styling even when
html5.css is used as the default stylesheet.
(Users liking the "web page" look can still get it
by enabling some of our existing style tweaks.)
3 months ago
poire-z 70e6f4ce09 util.prettifyCSS(): handle better :is() and similar 3 months ago
poire-z e3d7669588 Style tweaks: add tweak to avoid some presentational hints 3 months ago
poire-z 9467034f3f ReaderTypeset: tweak Style> menu logic and defaults
- Reword and document most menu items.
- Handle internally two default styles, one applying only
  to FB2/FB2 books, and the other to all other formats.
- Also don't reset the stylesheet to epub.css when
  toggling Embedded Styles to off.
3 months ago
poire-z 93b3e3504d bump crengine: better conformance to the HTML Standard rendering
Includes:
- Hyphenation: update French.pattern
- [CI] Add stylelint to help prevent typos in CSS
- In-page footnotes: better handle duplicated ids
- lvrend: handle in-page footnotes in table <caption>
- lvstsheet: fix compiler warnings
- LVString: ignore CJK chars in lStr_findWordBounds()
- lvtext: AddLine(): handle some CJK + space edge case
- EPUB: look for EPUB3 cover even when EPUB2 cover advertized
- List items: proper per-specs positionning and sizing
- epub.css: add/use "@media (-cr-max-cre-dom-version: 20180527)"
- fb2def.h: add more HTML element and attributes names
- CSS: generic support for handling presentational hints
- CSS: add support for private -cr-apply-func:
- ldomDocumentWriterFilter: remove attribute to CSS conversion
- lvrend: more proper rendering of block images
- lvrend: keep margin_left/right updated when "auto"
- CSS: add support for handling HTML's align= attribute
- lvrend: fix HR and images positionning when floats involved
- epub.css, html5.css: minor updates for easier stylesheet switch
- epub.css, html5.css: major updates for better conformance
- fb2.css: fix CI stylelint warnings
Also update to libunibreak 6.0.
3 months ago
hius07 6f896e9383
ReaderFooter: chapter progress bar (#11505) 3 months ago
hius07 bdb1c3135c
Fulltext search: default mode, fixes (#11507) 3 months ago
hius07 8df885438c
Bookmarks: edit highlighted text (#11484) 3 months ago
hius07 66afeebe85
CoverBrowser: show cached cover of deleted file in history (#11523) 3 months ago
poire-z c65d128032
Menu, DictQuickLookup, TextViewer: allow mousewheel scrolling (#11525)
We also need to catch it in TrapWidget so we can
interrupt Wikipedia articles images loading.
3 months ago
zwim c8f39c3841
Merge pull request #11498 from zwim/optimize_rounded
UI: optimize and anti-alias rounded rectangles
3 months ago
zwim 58b3367d18 anti alias rounded corners in UI 3 months ago
zwim 764f8ba647 bump base: Use Bresenham's algorithm and anti-aliasing for rounded corners 3 months ago
NiLuJe dd8560cef8
Input: Don't let wacom pens clobber the slot of the next contact (#11520)
If there's only one contact, we won't get an ABS_MT_SLOT, so we need to
make sure we fall back to the main finger slot once we've caught a tool
switch.

Also, move the dedicated pen slot further away, so it has zero chance of
being detected as a potential buddy contact to a finger contact.

Fix #11514
3 months ago

@ -15,7 +15,7 @@ if [ -z "${CIRCLE_PULL_REQUEST}" ] && [ "${CIRCLE_BRANCH}" = 'master' ]; then
if [ "${CIRCLE_NODE_INDEX}" = 0 ]; then
travis_retry make coverage
pushd koreader-*/koreader && {
pushd install/koreader && {
# see https://github.com/codecov/example-lua
bash <(curl -s https://codecov.io/bash)
} && popd || exit

@ -4,4 +4,11 @@ CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=/dev/null
source "${CI_DIR}/common.sh"
make all
# Build.
cmd=(make all)
if [[ -d base/build ]]; then
cmd+=(--assume-old=base)
fi
"${cmd[@]}"
# vim: sw=4

@ -60,16 +60,3 @@ retry_cmd() {
set -e
return ${result}
}
# export CI_BUILD_DIR=${TRAVIS_BUILD_DIR}
# use eval to get fully expanded path
eval CI_BUILD_DIR="${CIRCLE_WORKING_DIRECTORY}"
export CI_BUILD_DIR
test -e "${HOME}/bin" || mkdir "${HOME}/bin"
export PATH=${PWD}/bin:${HOME}/bin:${PATH}
export PATH=${PATH}:${CI_BUILD_DIR}/install/bin
if [ -f "${CI_BUILD_DIR}/install/bin/luarocks" ]; then
# add local rocks to $PATH
eval "$(luarocks path --bin)"
fi

@ -1,22 +0,0 @@
#!/usr/bin/env bash
CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=/dev/null
source "${CI_DIR}/common.sh"
rm -rf "${HOME}/.luarocks"
mkdir "${HOME}/.luarocks"
cp "${CI_BUILD_DIR}/install/etc/luarocks/config.lua" "${HOME}/.luarocks/config.lua"
echo "wrap_bin_scripts = false" >>"${HOME}/.luarocks/config.lua"
travis_retry luarocks --local install luafilesystem
# for verbose_print module
travis_retry luarocks --local install ansicolors
travis_retry luarocks --local install busted 2.0.0-1
#- mv -f $HOME/.luarocks/bin/busted_bootstrap $HOME/.luarocks/bin/busted
travis_retry luarocks --local install luacheck 0.25.0-1
travis_retry luarocks --local install lanes # for parallel luacheck
# used only on master branch but added to cache for better speed
travis_retry luarocks --local install ldoc
travis_retry luarocks --local install luacov

@ -1,69 +0,0 @@
#!/usr/bin/env bash
CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=/dev/null
source "${CI_DIR}/common.sh"
# print some useful info
echo "BUILD_DIR: ${CI_BUILD_DIR}"
echo "pwd: $(pwd)"
ls
# toss submodules if there are any changes
# if [ "$(git status --ignore-submodules=dirty --porcelain)" ]; then
# "--ignore-submodules=dirty", removed temporarily, as it did not notice as
# expected that base was updated and kept using old cached base
if [ "$(git status --ignore-submodules=dirty --porcelain)" ]; then
# what changed?
git status
# purge and reinit submodules
git submodule deinit -f .
git submodule update --init
else
echo -e "${ANSI_GREEN}Using cached submodules."
fi
# install our own updated luarocks
echo "luarocks installation path: ${CI_BUILD_DIR}"
if [ ! -f "${CI_BUILD_DIR}/install/bin/luarocks" ]; then
git clone https://github.com/torch/luajit-rocks.git
pushd luajit-rocks && {
git checkout 6529891
cmake . -DWITH_LUAJIT21=ON -DCMAKE_INSTALL_PREFIX="${CI_BUILD_DIR}/install"
make install
} && popd || exit
else
echo -e "${ANSI_GREEN}Using cached luarocks."
fi
if [ ! -d "${HOME}/.luarocks" ] || [ ! -f "${HOME}/.luarocks/$(md5sum <"${CI_DIR}/helper_luarocks.sh")" ]; then
echo -e "${ANSI_GREEN}Grabbing new .luarocks."
sudo apt-get update
# install openssl devel for luasec
sudo apt-get -y install libssl-dev
"${CI_DIR}/helper_luarocks.sh"
touch "${HOME}/.luarocks/$(md5sum <"${CI_DIR}/helper_luarocks.sh")"
else
echo -e "${ANSI_GREEN}Using cached .luarocks."
fi
#install our own updated shellcheck
SHELLCHECK_VERSION="v0.8.0"
SHELLCHECK_URL="https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION?}/shellcheck-${SHELLCHECK_VERSION?}.linux.x86_64.tar.xz"
if ! command -v shellcheck; then
curl -sSL "${SHELLCHECK_URL}" | tar --exclude 'SHA256SUMS' --strip-components=1 -C "${HOME}/bin" -xJf -
chmod +x "${HOME}/bin/shellcheck"
shellcheck --version
else
echo -e "${ANSI_GREEN}Using cached shellcheck."
fi
# install shfmt
SHFMT_URL="https://github.com/mvdan/sh/releases/download/v3.2.0/shfmt_v3.2.0_linux_amd64"
if [ "$(shfmt --version)" != "v3.2.0" ]; then
curl -sSL "${SHFMT_URL}" -o "${HOME}/bin/shfmt"
chmod +x "${HOME}/bin/shfmt"
else
echo -e "${ANSI_GREEN}Using cached shfmt."
fi

@ -4,9 +4,11 @@ CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=/dev/null
source "${CI_DIR}/common.sh"
pushd koreader-emulator-x86_64-linux-gnu/koreader && {
pushd install/koreader && {
# the circleci command spits out newlines; we want spaces instead
BUSTED_SPEC_FILE="$(circleci tests glob "spec/front/unit/*_spec.lua" | circleci tests split --split-by=timings --timings-type=filename | tr '\n' ' ')"
} && popd || exit
make testfront BUSTED_SPEC_FILE="${BUSTED_SPEC_FILE}"
# vim: sw=4

@ -1,112 +1,165 @@
version: 2
version: "2.1"
workflows:
version: 2
build:
jobs:
- build
- docs:
context: koreader-vars
filters:
branches:
only: master
requires:
- build
# Parameters. {{{
jobs:
build:
parameters:
# Bump this to reset all caches.
cache_epoch:
type: integer
default: 0
# }}}
# Executors. {{{
executors:
base:
docker:
- image: koreader/kobase:0.3.0
- image: koreader/kobase:0.3.2-20.04
auth:
username: $DOCKER_USERNAME
password: $DOCKER_PASSWORD
environment:
EMULATE_READER: 1
# }}}
# Jobs. {{{
jobs:
# Build. {{{
build:
executor: base
resource_class: medium
environment:
BASH_ENV: "~/.bashrc"
CCACHE_MAXSIZE: "256M"
CLICOLOR_FORCE: "1"
EMULATE_READER: "1"
MAKEFLAGS: "OUTPUT_DIR=build INSTALL_DIR=install"
parallelism: 2
steps:
# Checkout / fetch. {{{
- checkout
- run:
name: Fetch
command: .ci/fetch.sh
# }}}
# Check.
- run:
name: Check
command: .ci/check.sh
# Restore / setup caches. {{{
- run:
name: Generate cache key
command: make -C base TARGET= cache-key
- restore_cache:
name: Restore build directory
keys:
# binary dependencies require {{ arch }} because there are different CPUs in use on the servers
- deps-{{ arch }}-{{ checksum ".ci/install.sh" }}-{{ checksum ".ci/helper_luarocks.sh" }}
# need to init some stuff first or git will complain when sticking in base cache
- run: git submodule init base && git submodule update base && pushd base && git submodule init && git submodule update && popd
# we can't use command output directly for cache check so we write it to git-rev-base
- run: pushd base && git_rev_base=$(git describe HEAD) && popd && echo $git_rev_base && echo $git_rev_base >git-rev-base
- &CACHE_KEY_BUILD_DIR '<< pipeline.parameters.cache_epoch >>-{{ .Environment.CIRCLE_JOB }}-build-{{ arch }}-{{ checksum "base/cache-key" }}'
- restore_cache:
name: Restore build cache
keys:
- build-{{ arch }}-{{ checksum "git-rev-base" }}
- run: echo 'export PATH=${HOME}/bin:${PATH}' >> $BASH_ENV
# installs and caches testing tools
- run:
name: install
command: .ci/install.sh
- save_cache:
key: deps-{{ arch }}-{{ checksum ".ci/install.sh" }}-{{ checksum ".ci/helper_luarocks.sh" }}
paths:
- "/home/ko/bin"
- "/home/ko/.luarocks"
# compiled luarocks binaries
- "install"
# installs everything and caches base
- &CACHE_KEY_BUILD_CACHE '<< pipeline.parameters.cache_epoch >>-{{ .Environment.CIRCLE_JOB }}-ccache-{{ arch }}-{{ checksum "base/cache-key" }}'
- '<< pipeline.parameters.cache_epoch >>-{{ .Environment.CIRCLE_JOB }}-ccache-{{ arch }}-'
- run:
name: fetch
command: .ci/fetch.sh
name: Setup build cache
command: |
set -x
which ccache
ccache --version
ccache --zero-stats
ccache --show-config
# }}}
# Build.
- run:
name: check
command: .ci/check.sh
- run:
name: build
name: Build
command: .ci/build.sh
# we want to save cache prior to testing so we don't have to clean it up
# Clean / save caches. {{{
# We want to save cache prior to testing so we don't have to clean it up.
- run:
name: Clean caches
when: always
command: |
set -x
# Trim the build directory.
rm -rf base/build/{cmake,staging,thirdparty}
ccache --cleanup >/dev/null
ccache --show-stats
- save_cache:
key: build-{{ arch }}-{{ checksum "git-rev-base" }}
name: Save build cache
key: *CACHE_KEY_BUILD_CACHE
paths:
- "/home/ko/.ccache"
- "base"
# our lovely unit tests
- /home/ko/.ccache
- save_cache:
name: Save build directory
key: *CACHE_KEY_BUILD_DIR
paths:
- base/build
# }}}
# Tests / coverage. {{{
# Our lovely unit tests.
- run:
name: test
name: Test
command: .ci/test.sh
# docs, coverage, and test timing (can we use two outputs at once?); master branch only
# Docs, coverage, and test timing (can we use two outputs at once?); master branch only.
- run:
name: coverage
name: Coverage
command: .ci/after_success.sh
# by storing the test results CircleCI automatically distributes tests based on execution time
# By storing the test results CircleCI automatically distributes tests based on execution time.
- store_test_results:
path: koreader-emulator-x86_64-linux-gnu/koreader
# CircleCI doesn't make the test results available as artifacts (October 2017)
path: &TESTS_XML install/koreader/junit-test-results.xml
# CircleCI doesn't make the test results available as artifacts (October 2017).
- store_artifacts:
path: koreader-emulator-x86_64-linux-gnu/koreader/junit-test-results.xml
path: *TESTS_XML
# }}}
# }}}
# Docs. {{{
docs:
docker:
- image: koreader/kobase:0.3.0
auth:
username: $DOCKER_USERNAME
password: $DOCKER_PASSWORD
environment:
EMULATE_READER: 1
executor: base
resource_class: small
environment:
BASH_ENV: "~/.bashrc"
parallelism: 1
steps:
- checkout
- restore_cache:
keys:
# binary dependencies require {{ arch }} because there are different CPUs in use on the servers
- deps-{{ arch }}-{{ checksum ".ci/install.sh" }}-{{ checksum ".ci/helper_luarocks.sh" }}
# need to init some stuff first or git will complain when sticking in base cache
- run: git submodule init base && git submodule update base && pushd base && git submodule init && git submodule update && popd
# we can't use command output directly for cache check so we write it to git-rev-base
- run: pushd base && git_rev_base=$(git describe HEAD) && popd && echo $git_rev_base && echo $git_rev_base >git-rev-base
- run:
name: init-submodules
command: git submodule init && git submodule sync && git submodule update
name: fetch
command: .ci/fetch.sh
# docs, coverage, and test timing (can we use two outputs at once?); master branch only
- run:
name: docs-and-translation
command: .ci/after_success_docs_translation.sh
# }}}
# }}}
# Workflows. {{{
workflows:
version: 2
build:
jobs:
- build
- docs:
context: koreader-vars
filters:
branches:
only: master
requires:
- build
# }}}
# vim: foldmethod=marker foldlevel=0

@ -1,12 +1,18 @@
name: build
name: macos
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on: [push, pull_request]
permissions:
contents: read
defaults:
run:
shell: bash
jobs:
macos_build:
macos:
# macos-11, macos-12 & macos-13 are broken at this time being.
# https://github.com/koreader/koreader/issues/8686,
@ -17,31 +23,159 @@ jobs:
# 10.15 is no longer supported so we are running 13 just to make sure the build does not break.
runs-on: macos-13
env:
# Bump number to reset all caches.
CACHE_EPOCH: '0'
CLICOLOR_FORCE: '1'
MACOSX_DEPLOYMENT_TARGET: '10.15'
MAKEFLAGS: 'OUTPUT_DIR=build INSTALL_DIR=install TARGET=macos'
steps:
- name: XCode version
run: xcode-select -p
- name: Check out Git repository
# Checkout / fetch. {{{
- name: Checkout
uses: actions/checkout@v4
with:
clean: false
fetch-depth: 0
filter: tree:0
show-progress: false
- name: Fetch
run: make fetchthirdparty
# }}}
# Restore / setup caches. {{{
- name: Generate cache key
run: make -C base TARGET= cache-key
- name: Restore build directory
id: build-restore
uses: actions/cache/restore@v4
with:
path: base/build
key: ${{ env.CACHE_EPOCH }}-${{ runner.os }}-build-${{ hashFiles('base/cache-key') }}
- name: Homebrew install dependencies
# Compared to the README, adds ccache for faster compilation times
# Compared to the emulator, adds p7zip.
- name: Restore build cache
id: ccache-restore
if: steps.build-restore.outputs.cache-hit != 'true'
uses: actions/cache/restore@v4
with:
path: /Users/runner/Library/Caches/ccache
key: ${{ env.CACHE_EPOCH }}-${{ runner.os }}-ccache-${{ hashFiles('base/cache-key') }}
restore-keys: ${{ env.CACHE_EPOCH }}-${{ runner.os }}-ccache-
- name: Install ccache
if: steps.build-restore.outputs.cache-hit != 'true'
run: |
wget --progress=dot:mega https://github.com/ccache/ccache/releases/download/v4.9.1/ccache-4.9.1-darwin.tar.gz
tar xf ccache-4.9.1-darwin.tar.gz
printf '%s\n' "$PWD/ccache-4.9.1-darwin" >>"${GITHUB_PATH}"
- name: Setup build cache
if: steps.build-restore.outputs.cache-hit != 'true'
run: |
set -x
which ccache
ccache --version
ccache --zero-stats
ccache --max-size=256M
ccache --show-config
# }}}
# Install dependencies. {{{
- name: Setup Python
if: steps.build-restore.outputs.cache-hit != 'true'
uses: actions/setup-python@v5
with:
# Note: Python 3.12 removal of `distutils` breaks GLib's build.
python-version: '3.11'
- name: Install homebrew dependencies
# Compared to the README, adds p7zip.
run: |
packages=(
nasm binutils coreutils libtool autoconf automake cmake make
sdl2 lua@5.1 luarocks gettext pkg-config wget
gnu-getopt grep p7zip ninja
)
# Lua 5.1 is disabled, so we need to work around that:
# - fetch all packages
brew fetch "${packages[@]}"
# - disable auto-updates
export HOMEBREW_NO_AUTO_UPDATE=1
# - install lua@5.1 from cache
brew install "$(brew --cache lua@5.1)"
# - and install the rest
brew install "${packages[@]}"
- name: Update PATH
run: >
brew install -q nasm ragel binutils coreutils libtool autoconf automake cmake makedepend
sdl2 lua@5.1 luarocks gettext pkg-config wget gnu-getopt grep bison
ccache p7zip
printf '%s\n'
"$(brew --prefix)/opt/gettext/bin"
"$(brew --prefix)/opt/gnu-getopt/bin"
"$(brew --prefix)/opt/grep/libexec/gnubin"
"$(brew --prefix)/opt/make/libexec/gnubin"
| tee "${GITHUB_PATH}"
# }}}
# Build. {{{
- name: Build
if: steps.build-restore.outputs.cache-hit != 'true'
run: make base
- name: Dump binaries runtime path & dependencies
run: make bindeps
# }}}
# Clean / save caches. {{{
- name: Building in progress…
- name: Clean caches
if: steps.build-restore.outputs.cache-hit != 'true' && always()
run: |
export MACOSX_DEPLOYMENT_TARGET=10.15;
export PATH="$(brew --prefix)/opt/gettext/bin:$(brew --prefix)/opt/gnu-getopt/bin:$(brew --prefix)/opt/bison/bin:$(brew --prefix)/opt/grep/libexec/gnubin:${PATH}";
./kodev release macos
set -x
# Trim the build directory.
rm -rf base/build/{cmake,staging,thirdparty}
ccache --cleanup >/dev/null
ccache --show-stats --verbose
- name: Uploading artifacts
- name: Save build cache
uses: actions/cache/save@v4
if: steps.build-restore.outputs.cache-hit != 'true' && steps.ccache-restore.outputs.cache-hit != 'true'
with:
path: /Users/runner/Library/Caches/ccache
key: ${{ steps.ccache-restore.outputs.cache-primary-key }}
- name: Save build directory
uses: actions/cache/save@v4
if: steps.build-restore.outputs.cache-hit != 'true'
with:
path: base/build
key: ${{ steps.build-restore.outputs.cache-primary-key }}
# }}}
# Generate / upload artifact. {{{
- name: Generate artifact
run: make update --assume-old=base
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: koreader-macos
path: '*.7z'
# }}}
# vim: foldmethod=marker foldlevel=0

1
.gitmodules vendored

@ -18,3 +18,4 @@
[submodule "l10n"]
path = l10n
url = https://github.com/koreader/koreader-translations.git
shallow = true

@ -1,48 +0,0 @@
language: c
# sudo: false
sudo: true
dist: trusty
compiler:
- gcc
env:
global:
- "PATH=${HOME}/bin:${PATH}"
matrix:
- EMULATE_READER=1
cache:
apt: true
directories:
- "${HOME}/bin"
# compiled luarocks binaries
- "${TRAVIS_BUILD_DIR}/install"
# base build
- "${TRAVIS_BUILD_DIR}/base"
- "${HOME}/.ccache"
- "${HOME}/.luarocks"
before_cache:
# don't quote like you normally would or it won't expand
- rm -frv ${TRAVIS_BUILD_DIR}/base/build/*/cache/*
# don't cache unit tests
- rm -frv ${TRAVIS_BUILD_DIR}/base/build/*/spec
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- libsdl1.2-dev
# luasec dependencies
- libssl1.0.0
- nasm
# OpenSSL likes this (package contains makedepend)
- xutils-dev
before_install: .ci/before_install.sh
install: .ci/install.sh
script: .ci/script.sh
after_success: .ci/after_success.sh

@ -1,20 +1,21 @@
PHONY = all android-ndk android-sdk base clean coverage doc fetchthirdparty po pot static-check test testfront
# koreader-base directory
KOR_BASE?=base
# the repository might not have been checked out yet, so make this
# able to fail:
-include $(KOR_BASE)/Makefile.defs
include $(KOR_BASE)/Makefile.defs
RELEASE_DATE := $(shell git show -s --format=format:"%cd" --date=short HEAD)
# We want VERSION to carry the version of the KOReader main repo, not that of koreader-base
VERSION:=$(shell git describe HEAD)
VERSION := $(shell git describe HEAD)
# Only append date if we're not on a whole version, like v2018.11
ifneq (,$(findstring -,$(VERSION)))
VERSION:=$(VERSION)_$(shell git describe HEAD | xargs git show -s --format=format:"%cd" --date=short)
VERSION := $(VERSION)_$(RELEASE_DATE)
endif
# releases do not contain tests and misc data
IS_RELEASE := $(if $(or $(EMULATE_READER),$(WIN32)),,1)
IS_RELEASE := $(if $(or $(IS_RELEASE),$(APPIMAGE),$(DEBIAN),$(MACOS)),1,)
IS_RELEASE := $(if $(or $(IS_RELEASE),$(APPIMAGE),$(LINUX),$(MACOS)),1,)
ifeq ($(ANDROID_ARCH), arm64)
ANDROID_ABI?=arm64-v8a
@ -31,7 +32,18 @@ endif
ANDROID_VERSION?=$(shell git rev-list --count HEAD)
ANDROID_NAME?=$(VERSION)
MACHINE=$(shell $(CC) -dumpmachine 2>/dev/null)
LINUX_ARCH?=native
ifeq ($(LINUX_ARCH), native)
LINUX_ARCH_NAME:=$(shell uname -m)
else ifeq ($(LINUX_ARCH), arm64)
LINUX_ARCH_NAME:=aarch64
else ifeq ($(LINUX_ARCH), arm)
LINUX_ARCH_NAME:=armv7l
endif
LINUX_ARCH_NAME?=$(LINUX_ARCH)
MACHINE=$(TARGET_MACHINE)
ifdef KODEBUG
MACHINE:=$(MACHINE)-debug
KODEDUG_SUFFIX:=-debug
@ -43,72 +55,51 @@ else
DIST:=emulator
endif
INSTALL_DIR=koreader-$(DIST)-$(MACHINE)
INSTALL_DIR ?= koreader-$(DIST)-$(MACHINE)
# platform directories
PLATFORM_DIR=platform
COMMON_DIR=$(PLATFORM_DIR)/common
ANDROID_DIR=$(PLATFORM_DIR)/android
ANDROID_LAUNCHER_DIR:=$(ANDROID_DIR)/luajit-launcher
ANDROID_ASSETS:=$(ANDROID_LAUNCHER_DIR)/assets/module
ANDROID_LIBS_ROOT:=$(ANDROID_LAUNCHER_DIR)/libs
ANDROID_LIBS_ABI:=$(ANDROID_LIBS_ROOT)/$(ANDROID_ABI)
APPIMAGE_DIR=$(PLATFORM_DIR)/appimage
CERVANTES_DIR=$(PLATFORM_DIR)/cervantes
DEBIAN_DIR=$(PLATFORM_DIR)/debian
KINDLE_DIR=$(PLATFORM_DIR)/kindle
KOBO_DIR=$(PLATFORM_DIR)/kobo
MACOS_DIR=$(PLATFORM_DIR)/mac
POCKETBOOK_DIR=$(PLATFORM_DIR)/pocketbook
REMARKABLE_DIR=$(PLATFORM_DIR)/remarkable
SONY_PRSTUX_DIR=$(PLATFORM_DIR)/sony-prstux
UBUNTUTOUCH_DIR=$(PLATFORM_DIR)/ubuntu-touch
UBUNTUTOUCH_SDL_DIR:=$(UBUNTUTOUCH_DIR)/ubuntu-touch-sdl
WIN32_DIR=$(PLATFORM_DIR)/win32
# appimage setup
APPIMAGETOOL=appimagetool-x86_64.AppImage
APPIMAGETOOL_URL=https://github.com/AppImage/AppImageKit/releases/download/12/appimagetool-x86_64.AppImage
# set to 1 if in Docker
DOCKER:=$(shell grep -q docker /proc/1/cgroup 2>/dev/null && echo 1)
# files to link from main directory
INSTALL_FILES=reader.lua setupkoenv.lua frontend resources defaults.lua datastorage.lua \
l10n tools README.md COPYING
all: $(if $(ANDROID),,$(KOR_BASE)/$(OUTPUT_DIR)/luajit)
$(MAKE) -C $(KOR_BASE)
ifeq ($(abspath $(OUTPUT_DIR)),$(OUTPUT_DIR))
ABSOLUTE_OUTPUT_DIR = $(OUTPUT_DIR)
else
ABSOLUTE_OUTPUT_DIR = $(KOR_BASE)/$(OUTPUT_DIR)
endif
OUTPUT_DIR_ARTIFACTS = $(ABSOLUTE_OUTPUT_DIR)/!(cache|cmake|history|staging|thirdparty)
all: base
install -d $(INSTALL_DIR)/koreader
rm -f $(INSTALL_DIR)/koreader/git-rev; echo "$(VERSION)" > $(INSTALL_DIR)/koreader/git-rev
ifdef ANDROID
rm -f android-fdroid-version; echo -e "$(ANDROID_NAME)\n$(ANDROID_VERSION)" > koreader-android-fdroid-latest
endif
ifeq ($(IS_RELEASE),1)
$(RCP) -fL $(KOR_BASE)/$(OUTPUT_DIR)/. $(INSTALL_DIR)/koreader/.
bash -O extglob -c '$(RCP) -fL $(OUTPUT_DIR_ARTIFACTS) $(INSTALL_DIR)/koreader/'
else
cp -f $(KOR_BASE)/ev_replay.py $(INSTALL_DIR)/koreader/
@echo "[*] create symlink instead of copying files in development mode"
cd $(INSTALL_DIR)/koreader && \
bash -O extglob -c "ln -sf ../../$(KOR_BASE)/$(OUTPUT_DIR)/!(cache|history) ."
bash -O extglob -c '$(SYMLINK) $(OUTPUT_DIR_ARTIFACTS) $(INSTALL_DIR)/koreader/'
ifneq (,$(EMULATE_READER))
@echo "[*] install front spec only for the emulator"
cd $(INSTALL_DIR)/koreader/spec && test -e front || \
ln -sf ../../../../spec ./front
cd $(INSTALL_DIR)/koreader/spec/front/unit && test -e data || \
ln -sf ../../test ./data
$(SYMLINK) $(abspath spec) $(INSTALL_DIR)/koreader/spec/front
$(SYMLINK) $(abspath test) $(INSTALL_DIR)/koreader/spec/front/unit/data
endif
endif
for f in $(INSTALL_FILES); do \
ln -sf ../../$$f $(INSTALL_DIR)/koreader/; \
done
$(SYMLINK) $(abspath $(INSTALL_FILES)) $(INSTALL_DIR)/koreader/
ifdef ANDROID
cd $(INSTALL_DIR)/koreader && \
ln -sf ../../$(ANDROID_DIR)/*.lua .
$(SYMLINK) $(abspath $(ANDROID_DIR)/*.lua) $(INSTALL_DIR)/koreader/
endif
@echo "[*] Install update once marker"
@echo "# This file indicates that update once patches have not been applied yet." > $(INSTALL_DIR)/koreader/update_once.marker
ifdef WIN32
@echo "[*] Install runtime libraries for win32..."
cd $(INSTALL_DIR)/koreader && cp ../../$(WIN32_DIR)/*.dll .
$(SYMLINK) $(abspath $(WIN32_DIR)/*.dll) $(INSTALL_DIR)/koreader/
endif
ifdef SHIP_SHARED_STL
@echo "[*] Install C++ runtime..."
@ -117,36 +108,28 @@ ifdef SHIP_SHARED_STL
$(STRIP) --strip-unneeded $(INSTALL_DIR)/koreader/libs/$(notdir $(SHARED_STL_LIB))
endif
@echo "[*] Install plugins"
@# TODO: link istead of cp?
$(RCP) plugins/. $(INSTALL_DIR)/koreader/plugins/.
@# purge deleted plugins
for d in $$(ls $(INSTALL_DIR)/koreader/plugins); do \
test -d plugins/$$d || rm -rf $(INSTALL_DIR)/koreader/plugins/$$d ; done
$(SYMLINK) $(abspath plugins) $(INSTALL_DIR)/koreader/
@echo "[*] Install resources"
$(RCP) -pL resources/fonts/. $(INSTALL_DIR)/koreader/fonts/.
$(SYMLINK) $(abspath resources/fonts/*) $(INSTALL_DIR)/koreader/fonts/
install -d $(INSTALL_DIR)/koreader/{screenshots,data/{dict,tessdata},fonts/host,ota}
ifeq ($(IS_RELEASE),1)
@echo "[*] Clean up, remove unused files for releases"
rm -rf $(INSTALL_DIR)/koreader/data/{cr3.ini,cr3skin-format.txt,desktop,devices,manual}
endif
$(KOR_BASE)/$(OUTPUT_DIR)/luajit:
base:
$(MAKE) -C $(KOR_BASE)
$(INSTALL_DIR)/koreader/.busted: .busted
ln -sf ../../.busted $(INSTALL_DIR)/koreader
$(SYMLINK) $(abspath .busted) $@
$(INSTALL_DIR)/koreader/.luacov:
test -e $(INSTALL_DIR)/koreader/.luacov || \
ln -sf ../../.luacov $(INSTALL_DIR)/koreader
$(SYMLINK) $(abspath .luacov) $@
testfront: $(INSTALL_DIR)/koreader/.busted
# sdr files may have unexpected impact on unit testing
-rm -rf spec/unit/data/*.sdr
cd $(INSTALL_DIR)/koreader && ./luajit $(shell which busted) \
--sort-files \
--output=gtest \
--exclude-tags=notest $(BUSTED_OVERRIDES) $(BUSTED_SPEC_FILE)
cd $(INSTALL_DIR)/koreader && $(BUSTED_LUAJIT) $(BUSTED_OVERRIDES) $(BUSTED_SPEC_FILE)
test: $(INSTALL_DIR)/koreader/.busted
$(MAKE) -C $(KOR_BASE) test
@ -163,10 +146,21 @@ coverage: $(INSTALL_DIR)/koreader/.luacov
+$$(($$(grep -nm1 -e "^Summary$$" luacov.report.out|cut -d: -f1)-1)) \
luacov.report.out
fetchthirdparty:
$(KOR_BASE)/Makefile.defs fetchthirdparty:
git submodule init
git submodule sync
git submodule update
ifneq (,$(CI))
git submodule update --depth 1 --jobs 3
else
# Force shallow clones of submodules configured as such.
git submodule update --jobs 3 --depth 1 $(shell \
git config --file=.gitmodules --name-only --get-regexp '^submodule\.[^.]+\.shallow$$' true \
| sed 's/\.shallow$$/.path/' \
| xargs -n1 git config --file=.gitmodules \
)
# Update the rest.
git submodule update --jobs 3
endif
$(MAKE) -C $(KOR_BASE) fetchthirdparty
VERBOSE ?= @
@ -184,413 +178,10 @@ dist-clean: clean
$(MAKE) -C $(KOR_BASE) dist-clean
$(MAKE) -C doc clean
KINDLE_PACKAGE:=koreader-$(DIST)$(KODEDUG_SUFFIX)-$(VERSION).zip
KINDLE_PACKAGE_OTA:=koreader-$(DIST)$(KODEDUG_SUFFIX)-$(VERSION).targz
ZIP_EXCLUDE=-x "*.swp" -x "*.swo" -x "*.orig" -x "*.un~"
# Don't bundle launchpad on touch devices..
ifeq ($(TARGET), kindle-legacy)
KINDLE_LEGACY_LAUNCHER:=launchpad
# Include target specific rules.
ifneq (,$(wildcard make/$(TARGET).mk))
include make/$(TARGET).mk
endif
kindleupdate: all
# ensure that the binaries were built for ARM
file $(INSTALL_DIR)/koreader/luajit | grep ARM || exit 1
# remove old package if any
rm -f $(KINDLE_PACKAGE)
# Kindle launching scripts
ln -sf ../$(KINDLE_DIR)/extensions $(INSTALL_DIR)/
ln -sf ../$(KINDLE_DIR)/launchpad $(INSTALL_DIR)/
ln -sf ../../$(KINDLE_DIR)/koreader.sh $(INSTALL_DIR)/koreader
ln -sf ../../$(KINDLE_DIR)/libkohelper.sh $(INSTALL_DIR)/koreader
ln -sf ../../../../../$(KINDLE_DIR)/libkohelper.sh $(INSTALL_DIR)/extensions/koreader/bin
ln -sf ../../$(COMMON_DIR)/spinning_zsync $(INSTALL_DIR)/koreader
ln -sf ../../$(KINDLE_DIR)/wmctrl $(INSTALL_DIR)/koreader
# create new package
cd $(INSTALL_DIR) && pwd && \
zip -9 -r \
../$(KINDLE_PACKAGE) \
extensions koreader $(KINDLE_LEGACY_LAUNCHER) \
-x "koreader/resources/fonts/*" "koreader/ota/*" \
"koreader/resources/icons/src/*" "koreader/spec/*" \
$(ZIP_EXCLUDE)
# generate kindleupdate package index file
zipinfo -1 $(KINDLE_PACKAGE) > \
$(INSTALL_DIR)/koreader/ota/package.index
echo "koreader/ota/package.index" >> $(INSTALL_DIR)/koreader/ota/package.index
# update index file in zip package
cd $(INSTALL_DIR) && zip -u ../$(KINDLE_PACKAGE) \
koreader/ota/package.index
# make gzip kindleupdate for zsync OTA update
# note that the targz file extension is intended to keep ISP from caching
# the file, see koreader#1644.
cd $(INSTALL_DIR) && \
tar --hard-dereference -I"gzip --rsyncable" -cah --no-recursion -f ../$(KINDLE_PACKAGE_OTA) \
-T koreader/ota/package.index
KOBO_PACKAGE:=koreader-kobo$(KODEDUG_SUFFIX)-$(VERSION).zip
KOBO_PACKAGE_OTA:=koreader-kobo$(KODEDUG_SUFFIX)-$(VERSION).targz
koboupdate: all
# ensure that the binaries were built for ARM
file $(INSTALL_DIR)/koreader/luajit | grep ARM || exit 1
# remove old package if any
rm -f $(KOBO_PACKAGE)
# Kobo launching scripts
cp $(KOBO_DIR)/koreader.png $(INSTALL_DIR)/koreader.png
cp $(KOBO_DIR)/*.sh $(INSTALL_DIR)/koreader
cp $(COMMON_DIR)/spinning_zsync $(INSTALL_DIR)/koreader
# create new package
cd $(INSTALL_DIR) && \
zip -9 -r \
../$(KOBO_PACKAGE) \
koreader -x "koreader/resources/fonts/*" \
"koreader/resources/icons/src/*" "koreader/spec/*" \
$(ZIP_EXCLUDE)
# generate koboupdate package index file
zipinfo -1 $(KOBO_PACKAGE) > \
$(INSTALL_DIR)/koreader/ota/package.index
echo "koreader/ota/package.index" >> $(INSTALL_DIR)/koreader/ota/package.index
# update index file in zip package
cd $(INSTALL_DIR) && zip -u ../$(KOBO_PACKAGE) \
koreader/ota/package.index koreader.png README_kobo.txt
# make gzip koboupdate for zsync OTA update
cd $(INSTALL_DIR) && \
tar --hard-dereference -I"gzip --rsyncable" -cah --no-recursion -f ../$(KOBO_PACKAGE_OTA) \
-T koreader/ota/package.index
PB_PACKAGE:=koreader-pocketbook$(KODEDUG_SUFFIX)-$(VERSION).zip
PB_PACKAGE_OTA:=koreader-pocketbook$(KODEDUG_SUFFIX)-$(VERSION).targz
pbupdate: all
# ensure that the binaries were built for ARM
file $(INSTALL_DIR)/koreader/luajit | grep ARM || exit 1
# remove old package if any
rm -f $(PB_PACKAGE)
# Pocketbook launching scripts
mkdir -p $(INSTALL_DIR)/applications
mkdir -p $(INSTALL_DIR)/system/bin
cp $(POCKETBOOK_DIR)/koreader.app $(INSTALL_DIR)/applications
cp $(POCKETBOOK_DIR)/system_koreader.app $(INSTALL_DIR)/system/bin/koreader.app
cp $(COMMON_DIR)/spinning_zsync $(INSTALL_DIR)/koreader
cp -rfL $(INSTALL_DIR)/koreader $(INSTALL_DIR)/applications
find $(INSTALL_DIR)/applications/koreader \
-type f \( -name "*.gif" -o -name "*.html" -o -name "*.md" -o -name "*.txt" \) \
-exec rm -vf {} \;
# create new package
cd $(INSTALL_DIR) && \
zip -9 -r \
../$(PB_PACKAGE) \
applications -x "applications/koreader/resources/fonts/*" \
"applications/koreader/resources/icons/src/*" "applications/koreader/spec/*" \
$(ZIP_EXCLUDE)
# generate koboupdate package index file
zipinfo -1 $(PB_PACKAGE) > \
$(INSTALL_DIR)/applications/koreader/ota/package.index
echo "applications/koreader/ota/package.index" >> \
$(INSTALL_DIR)/applications/koreader/ota/package.index
# hack file path when running tar in parent directory of koreader
sed -i -e 's/^/..\//' \
$(INSTALL_DIR)/applications/koreader/ota/package.index
# update index file in zip package
cd $(INSTALL_DIR) && zip -ru ../$(PB_PACKAGE) \
applications/koreader/ota/package.index system
# make gzip pbupdate for zsync OTA update
cd $(INSTALL_DIR)/applications && \
tar --hard-dereference -I"gzip --rsyncable" -cah --no-recursion -f ../../$(PB_PACKAGE_OTA) \
-T koreader/ota/package.index
utupdate: all
# ensure that the binaries were built for ARM
file $(INSTALL_DIR)/koreader/luajit | grep ARM || exit 1
# remove old package if any
rm -f koreader-ubuntu-touch-$(MACHINE)-$(VERSION).click
ln -sf ../../$(UBUNTUTOUCH_DIR)/koreader.sh $(INSTALL_DIR)/koreader
ln -sf ../../$(UBUNTUTOUCH_DIR)/manifest.json $(INSTALL_DIR)/koreader
ln -sf ../../$(UBUNTUTOUCH_DIR)/koreader.apparmor $(INSTALL_DIR)/koreader
ln -sf ../../$(UBUNTUTOUCH_DIR)/koreader.apparmor.openstore $(INSTALL_DIR)/koreader
ln -sf ../../$(UBUNTUTOUCH_DIR)/koreader.desktop $(INSTALL_DIR)/koreader
ln -sf ../../$(UBUNTUTOUCH_DIR)/koreader.png $(INSTALL_DIR)/koreader
ln -sf ../../../$(UBUNTUTOUCH_DIR)/libSDL2.so $(INSTALL_DIR)/koreader/libs
# create new package
cd $(INSTALL_DIR) && pwd && \
zip -9 -r \
../koreader-$(DIST)-$(MACHINE)-$(VERSION).zip \
koreader -x "koreader/resources/fonts/*" "koreader/ota/*" \
"koreader/resources/icons/src/*" "koreader/spec/*" \
$(ZIP_EXCLUDE)
# generate ubuntu touch click package
rm -rf $(INSTALL_DIR)/tmp && mkdir -p $(INSTALL_DIR)/tmp
cd $(INSTALL_DIR)/tmp && \
unzip ../../koreader-$(DIST)-$(MACHINE)-$(VERSION).zip && \
click build koreader && \
mv *.click ../../koreader-$(DIST)-$(MACHINE)-$(VERSION).click
appimageupdate: all
# remove old package if any
rm -f koreader-appimage-$(MACHINE)-$(VERSION).appimage
ln -sf ../../$(APPIMAGE_DIR)/AppRun $(INSTALL_DIR)/koreader
ln -sf ../../$(APPIMAGE_DIR)/koreader.appdata.xml $(INSTALL_DIR)/koreader
ln -sf ../../$(APPIMAGE_DIR)/koreader.desktop $(INSTALL_DIR)/koreader
ln -sf ../../resources/koreader.png $(INSTALL_DIR)/koreader
# TODO at best this is DebUbuntu specific
ln -sf /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0 $(INSTALL_DIR)/koreader/libs/libSDL2.so
# required for our stock Ubuntu SDL even though we don't use sound
# the readlink is a half-hearted attempt at being generic; the echo libsndio.so.6.1 is specific to the nightly builds
ln -sf /usr/lib/x86_64-linux-gnu/$(shell readlink /usr/lib/x86_64-linux-gnu/libsndio.so || echo libsndio.so.6.1) $(INSTALL_DIR)/koreader/libs/
# also copy libbsd.so.0, cf. https://github.com/koreader/koreader/issues/4627
ln -sf /lib/x86_64-linux-gnu/libbsd.so.0 $(INSTALL_DIR)/koreader/libs/
ifeq ("$(wildcard $(APPIMAGETOOL))","")
# download appimagetool
wget "$(APPIMAGETOOL_URL)"
chmod a+x "$(APPIMAGETOOL)"
endif
ifeq ($(DOCKER), 1)
# remove previously extracted appimagetool, if any
rm -rf squashfs-root
./$(APPIMAGETOOL) --appimage-extract
endif
cd $(INSTALL_DIR) && pwd && \
rm -rf tmp && mkdir -p tmp && \
cp -Lr koreader tmp && \
rm -rf tmp/koreader/ota && \
rm -rf tmp/koreader/resources/icons/src && \
rm -rf tmp/koreader/spec
# generate AppImage
cd $(INSTALL_DIR)/tmp && \
ARCH=x86_64 ../../$(if $(DOCKER),squashfs-root/AppRun,$(APPIMAGETOOL)) koreader && \
mv *.AppImage ../../koreader-$(DIST)-$(MACHINE)-$(VERSION).AppImage
androidupdate: all
# Note: do not remove the module directory so there's no need
# for `mk7z.sh` to always recreate `assets.7z` from scratch.
rm -rfv $(ANDROID_LIBS_ROOT)
mkdir -p $(ANDROID_ASSETS) $(ANDROID_LIBS_ABI)
# APK version
echo $(VERSION) > $(ANDROID_ASSETS)/version.txt
# shared libraries are stored as raw assets
cp -pR $(INSTALL_DIR)/koreader/libs $(ANDROID_LAUNCHER_DIR)/assets
# in runtime luajit-launcher's libluajit.so will be loaded
rm -vf $(ANDROID_LAUNCHER_DIR)/assets/libs/libluajit.so
# binaries are stored as shared libraries to prevent W^X exception on Android 10+
# https://developer.android.com/about/versions/10/behavior-changes-10#execute-permission
cp -pR $(INSTALL_DIR)/koreader/sdcv $(ANDROID_LIBS_ABI)/libsdcv.so
echo "sdcv libsdcv.so" > $(ANDROID_ASSETS)/map.txt
# assets are compressed manually and stored inside the APK.
cd $(INSTALL_DIR)/koreader && \
./tools/mk7z.sh \
../../$(ANDROID_ASSETS)/koreader.7z \
"$$(git show -s --format='%ci')" \
-m0=lzma2 -mx=9 \
-- . \
'-x!cache' \
'-x!clipboard' \
'-x!data/dict' \
'-x!data/tessdata' \
'-x!history' \
'-x!l10n/templates' \
'-x!libs' \
'-x!ota' \
'-x!resources/fonts*' \
'-x!resources/icons/src*' \
'-x!rocks/bin' \
'-x!rocks/lib/luarocks' \
'-x!screenshots' \
'-x!sdcv' \
'-x!spec' \
'-x!tools' \
'-xr!.*' \
'-xr!COPYING' \
'-xr!NOTES.txt' \
'-xr!NOTICE' \
'-xr!README.md' \
;
# make the android APK
# Note: filter out the `--debug=…` make flag
# so the old crummy version provided by the
# NDK does not blow a gasket.
MAKEFLAGS='$(filter-out --debug=%,$(MAKEFLAGS))' \
$(MAKE) -C $(ANDROID_LAUNCHER_DIR) $(if $(KODEBUG), debug, release) \
ANDROID_APPNAME=KOReader \
ANDROID_VERSION=$(ANDROID_VERSION) \
ANDROID_NAME=$(ANDROID_NAME) \
ANDROID_FLAVOR=$(ANDROID_FLAVOR)
cp $(ANDROID_LAUNCHER_DIR)/bin/NativeActivity.apk \
koreader-android-$(ANDROID_ARCH)$(KODEDUG_SUFFIX)-$(VERSION).apk
debianupdate: all
mkdir -pv \
$(INSTALL_DIR)/debian/usr/bin \
$(INSTALL_DIR)/debian/usr/lib \
$(INSTALL_DIR)/debian/usr/share/pixmaps \
$(INSTALL_DIR)/debian/usr/share/applications \
$(INSTALL_DIR)/debian/usr/share/doc/koreader \
$(INSTALL_DIR)/debian/usr/share/man/man1
cp -pv resources/koreader.png $(INSTALL_DIR)/debian/usr/share/pixmaps
cp -pv $(DEBIAN_DIR)/koreader.desktop $(INSTALL_DIR)/debian/usr/share/applications
cp -pv $(DEBIAN_DIR)/copyright COPYING $(INSTALL_DIR)/debian/usr/share/doc/koreader
cp -pv $(DEBIAN_DIR)/koreader.sh $(INSTALL_DIR)/debian/usr/bin/koreader
cp -Lr $(INSTALL_DIR)/koreader $(INSTALL_DIR)/debian/usr/lib
gzip -cn9 $(DEBIAN_DIR)/changelog > $(INSTALL_DIR)/debian/usr/share/doc/koreader/changelog.Debian.gz
gzip -cn9 $(DEBIAN_DIR)/koreader.1 > $(INSTALL_DIR)/debian/usr/share/man/man1/koreader.1.gz
chmod 644 \
$(INSTALL_DIR)/debian/usr/share/doc/koreader/changelog.Debian.gz \
$(INSTALL_DIR)/debian/usr/share/doc/koreader/copyright \
$(INSTALL_DIR)/debian/usr/share/man/man1/koreader.1.gz
rm -rf \
$(INSTALL_DIR)/debian/usr/lib/koreader/{ota,cache,clipboard,screenshots,spec,tools,resources/fonts,resources/icons/src}
macosupdate: all
mkdir -p \
$(INSTALL_DIR)/bundle/Contents/MacOS \
$(INSTALL_DIR)/bundle/Contents/Resources
cp -pv $(MACOS_DIR)/koreader.icns $(INSTALL_DIR)/bundle/Contents/Resources/icon.icns
cp -LR $(INSTALL_DIR)/koreader $(INSTALL_DIR)/bundle/Contents
cp -pRv $(MACOS_DIR)/menu.xml $(INSTALL_DIR)/bundle/Contents/MainMenu.xib
ibtool --compile "$(INSTALL_DIR)/bundle/Contents/Resources/Base.lproj/MainMenu.nib" "$(INSTALL_DIR)/bundle/Contents/MainMenu.xib"
rm -rfv "$(INSTALL_DIR)/bundle/Contents/MainMenu.xib"
REMARKABLE_PACKAGE:=koreader-remarkable$(KODEDUG_SUFFIX)-$(VERSION).zip
REMARKABLE_PACKAGE_OTA:=koreader-remarkable$(KODEDUG_SUFFIX)-$(VERSION).targz
remarkableupdate: all
# ensure that the binaries were built for ARM
file $(INSTALL_DIR)/koreader/luajit | grep ARM || exit 1
# remove old package if any
rm -f $(REMARKABLE_PACKAGE)
# Remarkable scripts
cp $(REMARKABLE_DIR)/* $(INSTALL_DIR)/koreader
cp $(COMMON_DIR)/spinning_zsync $(INSTALL_DIR)/koreader
# create new package
cd $(INSTALL_DIR) && \
zip -9 -r \
../$(REMARKABLE_PACKAGE) \
koreader -x "koreader/resources/fonts/*" \
"koreader/resources/icons/src/*" "koreader/spec/*" \
$(ZIP_EXCLUDE)
# generate update package index file
zipinfo -1 $(REMARKABLE_PACKAGE) > \
$(INSTALL_DIR)/koreader/ota/package.index
echo "koreader/ota/package.index" >> $(INSTALL_DIR)/koreader/ota/package.index
# update index file in zip package
cd $(INSTALL_DIR) && zip -u ../$(REMARKABLE_PACKAGE) \
koreader/ota/package.index
# make gzip remarkable update for zsync OTA update
cd $(INSTALL_DIR) && \
tar -I"gzip --rsyncable" -cah --no-recursion -f ../$(REMARKABLE_PACKAGE_OTA) \
-T koreader/ota/package.index
SONY_PRSTUX_PACKAGE:=koreader-sony-prstux$(KODEDUG_SUFFIX)-$(VERSION).zip
SONY_PRSTUX_PACKAGE_OTA:=koreader-sony-prstux$(KODEDUG_SUFFIX)-$(VERSION).targz
sony-prstuxupdate: all
# ensure that the binaries were built for ARM
file $(INSTALL_DIR)/koreader/luajit | grep ARM || exit 1
# remove old package if any
rm -f $(SONY_PRSTUX_PACKAGE)
# Sony PRSTUX launching scripts
cp $(SONY_PRSTUX_DIR)/*.sh $(INSTALL_DIR)/koreader
# create new package
cd $(INSTALL_DIR) && \
zip -9 -r \
../$(SONY_PRSTUX_PACKAGE) \
koreader -x "koreader/resources/fonts/*" \
"koreader/resources/icons/src/*" "koreader/spec/*" \
$(ZIP_EXCLUDE)
# generate update package index file
zipinfo -1 $(SONY_PRSTUX_PACKAGE) > \
$(INSTALL_DIR)/koreader/ota/package.index
echo "koreader/ota/package.index" >> $(INSTALL_DIR)/koreader/ota/package.index
# update index file in zip package
cd $(INSTALL_DIR) && zip -u ../$(SONY_PRSTUX_PACKAGE) \
koreader/ota/package.index
# make gzip sonyprstux update for zsync OTA update
cd $(INSTALL_DIR) && \
tar --hard-dereference -I"gzip --rsyncable" -cah --no-recursion -f ../$(SONY_PRSTUX_PACKAGE_OTA) \
-T koreader/ota/package.index
CERVANTES_PACKAGE:=koreader-cervantes$(KODEDUG_SUFFIX)-$(VERSION).zip
CERVANTES_PACKAGE_OTA:=koreader-cervantes$(KODEDUG_SUFFIX)-$(VERSION).targz
cervantesupdate: all
# ensure that the binaries were built for ARM
file $(INSTALL_DIR)/koreader/luajit | grep ARM || exit 1
# remove old package if any
rm -f $(CERVANTES_PACKAGE)
# Cervantes launching scripts
cp $(COMMON_DIR)/spinning_zsync $(INSTALL_DIR)/koreader/spinning_zsync.sh
cp $(CERVANTES_DIR)/*.sh $(INSTALL_DIR)/koreader
cp $(CERVANTES_DIR)/spinning_zsync $(INSTALL_DIR)/koreader
# create new package
cd $(INSTALL_DIR) && \
zip -9 -r \
../$(CERVANTES_PACKAGE) \
koreader -x "koreader/resources/fonts/*" \
"koreader/resources/icons/src/*" "koreader/spec/*" \
$(ZIP_EXCLUDE)
# generate update package index file
zipinfo -1 $(CERVANTES_PACKAGE) > \
$(INSTALL_DIR)/koreader/ota/package.index
echo "koreader/ota/package.index" >> $(INSTALL_DIR)/koreader/ota/package.index
# update index file in zip package
cd $(INSTALL_DIR) && zip -u ../$(CERVANTES_PACKAGE) \
koreader/ota/package.index
# make gzip cervantes update for zsync OTA update
cd $(INSTALL_DIR) && \
tar --hard-dereference -I"gzip --rsyncable" -cah --no-recursion -f ../$(CERVANTES_PACKAGE_OTA) \
-T koreader/ota/package.index
update:
ifeq ($(TARGET), android)
make androidupdate
else ifeq ($(TARGET), appimage)
make appimageupdate
else ifeq ($(TARGET), cervantes)
make cervantesupdate
else ifeq ($(TARGET), kindle)
make kindleupdate
else ifeq ($(TARGET), kindle-legacy)
make kindleupdate
else ifeq ($(TARGET), kindlepw2)
make kindleupdate
else ifeq ($(TARGET), kobo)
make koboupdate
else ifeq ($(TARGET), pocketbook)
make pbupdate
else ifeq ($(TARGET), sony-prstux)
make sony-prstuxupdate
else ifeq ($(TARGET), remarkable)
make remarkableupdate
else ifeq ($(TARGET), ubuntu-touch)
make utupdate
else ifeq ($(TARGET), debian)
make debianupdate
$(CURDIR)/platform/debian/do_debian_package.sh $(INSTALL_DIR)
else ifeq ($(TARGET), debian-armel)
make debianupdate
$(CURDIR)/platform/debian/do_debian_package.sh $(INSTALL_DIR) armel
else ifeq ($(TARGET), debian-armhf)
make debianupdate
$(CURDIR)/platform/debian/do_debian_package.sh $(INSTALL_DIR) armhf
else ifeq ($(TARGET), debian-arm64)
make debianupdate
$(CURDIR)/platform/debian/do_debian_package.sh $(INSTALL_DIR) arm64
else ifeq ($(TARGET), macos)
make macosupdate
$(CURDIR)/platform/mac/do_mac_bundle.sh $(INSTALL_DIR)
endif
androiddev: androidupdate
$(MAKE) -C $(ANDROID_LAUNCHER_DIR) dev
android-ndk:
$(MAKE) -C $(KOR_BASE)/toolchain $(ANDROID_NDK_HOME)
@ -598,7 +189,6 @@ android-ndk:
android-sdk:
$(MAKE) -C $(KOR_BASE)/toolchain $(ANDROID_HOME)
# for gettext
DOMAIN=koreader
TEMPLATE_DIR=l10n/templates
@ -629,4 +219,10 @@ static-check:
doc:
make -C doc
.PHONY: all clean doc test update
.NOTPARALLEL:
.PHONY: $(PHONY)
LEFTOVERS = $(filter-out $(PHONY) $(INSTALL_DIR)/%,$(MAKECMDGOALS))
.PHONY: $(LEFTOVERS)
$(LEFTOVERS):
$(MAKE) -C $(KOR_BASE) $@

@ -1 +1 @@
Subproject commit 8f5f38d732bba170abdae5df015f9f4b475fac6e
Subproject commit 67474697169dd88800bc37af5b7fb87ce0596ee8

@ -17,7 +17,7 @@ function DataStorage:getDataDir()
local package_name = app_id:match("^(.-)_")
-- confined ubuntu app has write access to this dir
data_dir = string.format("%s/%s", os.getenv("XDG_DATA_HOME"), package_name)
elseif os.getenv("APPIMAGE") or os.getenv("KO_MULTIUSER") then
elseif os.getenv("APPIMAGE") or os.getenv("FLATPAK") or os.getenv("KO_MULTIUSER") then
if os.getenv("XDG_CONFIG_HOME") then
data_dir = string.format("%s/%s", os.getenv("XDG_CONFIG_HOME"), "koreader")
if lfs.attributes(os.getenv("XDG_CONFIG_HOME"), "mode") ~= "directory" then

@ -13,7 +13,7 @@ You can skip most of the following instructions if desired, and use our premade
To get and compile the source you must have `patch`, `wget`, `unzip`, `git`,
`cmake` and `luarocks` installed, as well as a version of `autoconf`
greater than 2.64. You also need `nasm`, `ragel`, and of course a compiler like `gcc`
greater than 2.64. You also need `nasm`, and of course a compiler like `gcc`
or `clang`.
### Debian/Ubuntu and derivates
@ -22,7 +22,7 @@ Install the prerequisites using APT:
```
sudo apt-get install build-essential git patch wget unzip \
gettext autoconf automake cmake libtool libtool-bin nasm ragel luarocks lua5.1 libsdl2-dev \
gettext autoconf automake cmake libtool libtool-bin nasm luarocks lua5.1 libsdl2-dev \
libssl-dev libffi-dev libc6-dev-i386 xutils-dev linux-libc-dev:i386 zlib1g:i386
```
@ -31,7 +31,7 @@ libssl-dev libffi-dev libc6-dev-i386 xutils-dev linux-libc-dev:i386 zlib1g:i386
Install the prerequisites using DNF:
```
sudo dnf install libstdc++-static SDL SDL-devel patch wget unzip git cmake luarocks autoconf nasm ragel gcc
sudo dnf install libstdc++-static SDL SDL-devel patch wget unzip git cmake luarocks autoconf nasm gcc
```
### macOS
@ -39,7 +39,7 @@ sudo dnf install libstdc++-static SDL SDL-devel patch wget unzip git cmake luaro
Install the prerequisites using [Homebrew](https://brew.sh/):
```
brew install nasm ragel binutils coreutils libtool autoconf automake cmake makedepend \
brew install nasm binutils coreutils libtool autoconf automake cmake makedepend \
sdl2 lua@5.1 luarocks gettext pkg-config wget gnu-getopt grep bison
```

@ -17,10 +17,10 @@ Each target has its own architecture and you'll need to setup a proper cross-com
A compatible version of the Android NDK and SDK will be downloaded automatically by `./kodev release android` if no NDK or SDK is provided in environment variables. For that purpose you can use:
```
NDK=/ndk/location SDK=/sdk/location ./kodev release android
ANDROID_NDK_HOME=/ndk/location ANDROID_HOME=/sdk/location ./kodev release android
```
If you want to use your own installed tools please make sure that you have the **NDKr15c** and the SDK for Android 9 (**API level 28**) already installed.
If you want to use your own installed tools please make sure that you have the **NDKr23c** and the SDK for Android 9 (**API level 28**) already installed.
#### for embedded linux devices

@ -23,6 +23,7 @@ local InputDialog = require("ui/widget/inputdialog")
local LanguageSupport = require("languagesupport")
local Menu = require("ui/widget/menu")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
local NetworkListener = require("ui/network/networklistener")
local PluginLoader = require("pluginloader")
local ReadCollection = require("readcollection")
local ReaderDeviceStatus = require("apps/reader/modules/readerdevicestatus")
@ -292,7 +293,7 @@ function FileManager:setupLayout()
table.insert(buttons, {}) -- separator
table.insert(buttons, {
filemanagerutil.genResetSettingsButton(doc_settings_or_file, close_dialog_refresh_callback),
filemanagerutil.genAddRemoveFavoritesButton(file, close_dialog_callback),
file_manager.collections:genAddToCollectionButton(file, close_dialog_callback, refresh_callback),
})
end
table.insert(buttons, {
@ -379,6 +380,9 @@ function FileManager:registerKeyEvents()
self.key_events.Home = { { "Home" } }
-- Override the menu.lua way of handling the back key
self.file_chooser.key_events.Back = { { Device.input.group.Back } }
if Device:hasScreenKB() then
self.key_events.KeyToggleWifi = { { "ScreenKB", "Home" }, event = "ToggleWifi" }
end
if not Device:hasFewKeys() then
-- Also remove the handler assigned to the "Back" key by menu.lua
self.file_chooser.key_events.Close = nil
@ -423,6 +427,7 @@ function FileManager:init()
self:registerModule("wikipedia", ReaderWikipedia:new{ ui = self })
self:registerModule("devicestatus", ReaderDeviceStatus:new{ ui = self })
self:registerModule("devicelistener", DeviceListener:new{ ui = self })
self:registerModule("networklistener", NetworkListener:new{ ui = self })
-- koreader plugins
for _, plugin_module in ipairs(PluginLoader:loadPlugins()) do
@ -438,11 +443,6 @@ function FileManager:init()
end
end
if Device:hasWifiToggle() then
local NetworkListener = require("ui/network/networklistener")
table.insert(self, NetworkListener:new{ ui = self })
end
self:initGesListener()
self:handleEvent(Event:new("SetDimensions", self.dimen))
@ -515,11 +515,17 @@ function FileManager:tapPlus()
local title, buttons
if self.select_mode then
local function toggle_select_mode_callback()
self:onToggleSelectMode()
end
local select_count = util.tableSize(self.selected_files)
local actions_enabled = select_count > 0
title = actions_enabled and T(N_("1 file selected", "%1 files selected", select_count), select_count)
or _("No files selected")
buttons = {
{
self.collections:genAddToCollectionButton(self.selected_files, close_dialog_callback, toggle_select_mode_callback),
},
{
{
text = _("Show selected files list"),
@ -725,7 +731,7 @@ function FileManager:reinit(path, focused_file)
UIManager:flushSettings()
self.dimen = Screen:getSize()
-- backup the root path and path items
self.root_path = path or self.file_chooser.path
self.root_path = BaseUtil.realpath(path or self.file_chooser.path)
local path_items_backup = {}
for k, v in pairs(self.file_chooser.path_items) do
path_items_backup[k] = v
@ -851,6 +857,10 @@ function FileManager:pasteFileFromClipboard(file)
local dest_path = BaseUtil.realpath(file or self.file_chooser.path)
dest_path = isFile(dest_path) and dest_path:match("(.*/)") or dest_path
local dest_file = BaseUtil.joinPath(dest_path, orig_name)
if orig_file == dest_file or orig_file == dest_path then -- do not paste to itself
self.clipboard = nil
return
end
local is_file = isFile(orig_file)
local function doPaste()
@ -942,19 +952,23 @@ function FileManager:pasteSelectedFiles(overwrite)
for orig_file in pairs(self.selected_files) do
local orig_name = BaseUtil.basename(orig_file)
local dest_file = BaseUtil.joinPath(dest_path, orig_name)
local ok
local dest_mode = lfs.attributes(dest_file, "mode")
if not dest_mode or (dest_mode == "file" and overwrite) then
if self.cutfile then
ok = self:moveFile(orig_file, dest_path)
else
ok = self:copyRecursive(orig_file, dest_path)
end
end
if ok then
DocSettings.updateLocation(orig_file, dest_file, not self.cutfile)
ok_files[orig_file] = true
if BaseUtil.realpath(orig_file) == dest_file then -- do not paste to itself
self.selected_files[orig_file] = nil
else
local ok
local dest_mode = lfs.attributes(dest_file, "mode")
if not dest_mode or (dest_mode == "file" and overwrite) then
if self.cutfile then
ok = self:moveFile(orig_file, dest_path)
else
ok = self:copyRecursive(orig_file, dest_path)
end
end
if ok then
DocSettings.updateLocation(orig_file, dest_file, not self.cutfile)
ok_files[orig_file] = true
self.selected_files[orig_file] = nil
end
end
end
local skipped_nb = util.tableSize(self.selected_files)
@ -1202,7 +1216,7 @@ function FileManager:showFiles(path, focused_file)
FileManager.instance:onClose()
end
path = path or G_reader_settings:readSetting("lastdir") or filemanagerutil.getDefaultDir()
path = BaseUtil.realpath(path or G_reader_settings:readSetting("lastdir") or filemanagerutil.getDefaultDir())
G_reader_settings:saveSetting("lastdir", path)
self:setRotationMode()
local file_manager = FileManager:new{

@ -1,19 +1,26 @@
local BD = require("ui/bidi")
local ButtonDialog = require("ui/widget/buttondialog")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local DocSettings = require("docsettings")
local DocumentRegistry = require("document/documentregistry")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local InfoMessage = require("ui/widget/infomessage")
local InputDialog = require("ui/widget/inputdialog")
local Menu = require("ui/widget/menu")
local ReadCollection = require("readcollection")
local SortWidget = require("ui/widget/sortwidget")
local UIManager = require("ui/uimanager")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local Screen = require("device").screen
local filemanagerutil = require("apps/filemanager/filemanagerutil")
local _ = require("gettext")
local T = require("ffi/util").template
local util = require("util")
local FileManagerCollection = WidgetContainer:extend{
title = _("Favorites"),
title = _("Collections"),
default_collection_title = _("Favorites"),
checkmark = "\u{2713}",
}
function FileManagerCollection:init()
@ -21,21 +28,73 @@ function FileManagerCollection:init()
end
function FileManagerCollection:addToMainMenu(menu_items)
menu_items.favorites = {
text = self.default_collection_title,
callback = function()
self:onShowColl()
end,
}
menu_items.collections = {
text = self.title,
callback = function()
self:onShowColl()
self:onShowCollList()
end,
}
end
function FileManagerCollection:updateItemTable()
-- collection
function FileManagerCollection:getCollectionTitle(collection_name)
return collection_name == ReadCollection.default_collection_name
and self.default_collection_title -- favorites
or collection_name
end
function FileManagerCollection:onShowColl(collection_name)
collection_name = collection_name or ReadCollection.default_collection_name
self.coll_menu = Menu:new{
ui = self.ui,
covers_fullscreen = true, -- hint for UIManager:_repaint()
is_borderless = true,
is_popout = false,
-- item and book cover thumbnail dimensions in Mosaic and Detailed list display modes
-- must be equal in File manager, History and Collection windows to avoid image scaling
title_bar_fm_style = true,
title_bar_left_icon = "appbar.menu",
onLeftButtonTap = function() self:showCollDialog() end,
onMenuChoice = self.onMenuChoice,
onMenuHold = self.onMenuHold,
onSetRotationMode = self.MenuSetRotationModeHandler,
_manager = self,
collection_name = collection_name,
}
self.coll_menu.close_callback = function()
if self.files_updated then
if self.ui.file_chooser then
self.ui.file_chooser:refreshPath()
end
self.files_updated = nil
end
UIManager:close(self.coll_menu)
self.coll_menu = nil
end
self:updateItemTable()
UIManager:show(self.coll_menu)
return true
end
function FileManagerCollection:updateItemTable(show_last_item)
local item_table = {}
for _, item in pairs(ReadCollection.coll[self.coll_menu.collection_name]) do
table.insert(item_table, item)
end
table.sort(item_table, function(v1, v2) return v1.order < v2.order end)
self.coll_menu:switchItemTable(self.title, item_table, -1)
if #item_table > 1 then
table.sort(item_table, function(v1, v2) return v1.order < v2.order end)
end
local title = self:getCollectionTitle(self.coll_menu.collection_name)
title = T("%1 (%2)", title, #item_table)
local item_number = show_last_item and #item_table or -1
self.coll_menu:switchItemTable(title, item_table, item_number)
end
function FileManagerCollection:onMenuChoice(item)
@ -92,7 +151,7 @@ function FileManagerCollection:onMenuHold(item)
table.insert(buttons, {
filemanagerutil.genResetSettingsButton(doc_settings_or_file, close_dialog_update_callback, is_currently_opened),
{
text = _("Remove from favorites"),
text = _("Remove from collection"),
callback = function()
UIManager:close(self.collfile_dialog)
ReadCollection:removeItem(file, self.collection_name)
@ -124,79 +183,37 @@ function FileManagerCollection:onMenuHold(item)
return true
end
function FileManagerCollection:MenuSetRotationModeHandler(rotation)
if rotation ~= nil and rotation ~= Screen:getRotationMode() then
UIManager:close(self._manager.coll_menu)
if self._manager.ui.view and self._manager.ui.view.onSetRotationMode then
self._manager.ui.view:onSetRotationMode(rotation)
elseif self._manager.ui.onSetRotationMode then
self._manager.ui:onSetRotationMode(rotation)
else
Screen:setRotationMode(rotation)
end
self._manager:onShowColl()
end
return true
end
function FileManagerCollection:onShowColl(collection_name)
collection_name = collection_name or ReadCollection.default_collection_name
self.coll_menu = Menu:new{
ui = self.ui,
covers_fullscreen = true, -- hint for UIManager:_repaint()
is_borderless = true,
is_popout = false,
-- item and book cover thumbnail dimensions in Mosaic and Detailed list display modes
-- must be equal in File manager, History and Collection windows to avoid image scaling
title_bar_fm_style = true,
title_bar_left_icon = "appbar.menu",
onLeftButtonTap = function() self:showCollDialog() end,
onMenuChoice = self.onMenuChoice,
onMenuHold = self.onMenuHold,
onSetRotationMode = self.MenuSetRotationModeHandler,
_manager = self,
collection_name = collection_name,
}
self.coll_menu.close_callback = function()
if self.files_updated then
if self.ui.file_chooser then
self.ui.file_chooser:refreshPath()
end
self.files_updated = nil
end
UIManager:close(self.coll_menu)
self.coll_menu = nil
end
self:updateItemTable()
UIManager:show(self.coll_menu)
return true
end
function FileManagerCollection:showCollDialog()
local coll_dialog
local buttons = {
{{
text = _("Sort favorites"),
text = _("Collections"),
callback = function()
UIManager:close(coll_dialog)
self.coll_menu.close_callback()
self:onShowCollList()
end,
}},
{}, -- separator
{{
text = _("Arrange books in collection"),
callback = function()
UIManager:close(coll_dialog)
self:sortCollection()
end,
}},
{{
text = _("Add a book to favorites"),
text = _("Add a book to collection"),
callback = function()
UIManager:close(coll_dialog)
local PathChooser = require("ui/widget/pathchooser")
local path_chooser = PathChooser:new{
path = G_reader_settings:readSetting("home_dir"),
select_directory = false,
file_filter = function(file)
return DocumentRegistry:hasProvider(file)
end,
onConfirm = function(file)
if not ReadCollection:hasFile(file) then
if not ReadCollection:isFileInCollection(file, self.coll_menu.collection_name) then
ReadCollection:addItem(file, self.coll_menu.collection_name)
self:updateItemTable()
self:updateItemTable(true) -- show added item
end
end,
}
@ -205,19 +222,20 @@ function FileManagerCollection:showCollDialog()
}},
}
if self.ui.document then
local has_file = ReadCollection:hasFile(self.ui.document.file)
local file = self.ui.document.file
local is_in_collection = ReadCollection:isFileInCollection(file, self.coll_menu.collection_name)
table.insert(buttons, {{
text_func = function()
return has_file and _("Remove current book from favorites") or _("Add current book to favorites")
return is_in_collection and _("Remove current book from collection") or _("Add current book to collection")
end,
callback = function()
UIManager:close(coll_dialog)
if has_file then
ReadCollection:removeItem(self.ui.document.file)
if is_in_collection then
ReadCollection:removeItem(file, self.coll_menu.collection_name)
else
ReadCollection:addItem(self.ui.document.file, self.coll_menu.collection_name)
ReadCollection:addItem(file, self.coll_menu.collection_name)
end
self:updateItemTable()
self:updateItemTable(not is_in_collection)
end,
}})
end
@ -228,12 +246,10 @@ function FileManagerCollection:showCollDialog()
end
function FileManagerCollection:sortCollection()
local item_table = ReadCollection:getOrderedCollection(self.coll_menu.collection_name)
local SortWidget = require("ui/widget/sortwidget")
local sort_widget
sort_widget = SortWidget:new{
title = _("Sort favorites"),
item_table = item_table,
title = _("Arrange books in collection"),
item_table = ReadCollection:getOrderedCollection(self.coll_menu.collection_name),
callback = function()
ReadCollection:updateCollectionOrder(self.coll_menu.collection_name, sort_widget.item_table)
self:updateItemTable()
@ -242,10 +258,341 @@ function FileManagerCollection:sortCollection()
UIManager:show(sort_widget)
end
function FileManagerCollection:MenuSetRotationModeHandler(rotation)
if rotation ~= nil and rotation ~= Screen:getRotationMode() then
UIManager:close(self._manager.coll_menu)
if self._manager.ui.view and self._manager.ui.view.onSetRotationMode then
self._manager.ui.view:onSetRotationMode(rotation)
elseif self._manager.ui.onSetRotationMode then
self._manager.ui:onSetRotationMode(rotation)
else
Screen:setRotationMode(rotation)
end
self._manager:onShowColl()
end
return true
end
function FileManagerCollection:onBookMetadataChanged()
if self.coll_menu then
self.coll_menu:updateItems()
end
end
-- collection list
function FileManagerCollection:onShowCollList(file_or_files, caller_callback, no_dialog)
self.selected_colections = nil
if file_or_files then -- select mode
if type(file_or_files) == "string" then -- checkmark collections containing the file
self.selected_colections = ReadCollection:getCollectionsWithFile(file_or_files)
else -- do not checkmark any
self.selected_colections = {}
end
end
self.coll_list = Menu:new{
subtitle = "",
covers_fullscreen = true,
is_borderless = true,
is_popout = false,
title_bar_fm_style = true,
title_bar_left_icon = file_or_files and "check" or "appbar.menu",
onLeftButtonTap = function() self:showCollListDialog(caller_callback, no_dialog) end,
onMenuChoice = self.onCollListChoice,
onMenuHold = self.onCollListHold,
onSetRotationMode = self.MenuSetRotationModeHandler,
_manager = self,
}
self.coll_list.close_callback = function(force_close)
if force_close or self.selected_colections == nil then
UIManager:close(self.coll_list)
self.coll_list = nil
end
end
self:updateCollListItemTable(true) -- init
UIManager:show(self.coll_list)
return true
end
function FileManagerCollection:updateCollListItemTable(do_init, item_number)
local item_table
if do_init then
item_table = {}
for name, coll in pairs(ReadCollection.coll) do
local mandatory
if self.selected_colections then
mandatory = self.selected_colections[name] and self.checkmark or " "
self.coll_list.items_mandatory_font_size = self.coll_list.font_size
else
mandatory = util.tableSize(coll)
end
table.insert(item_table, {
text = self:getCollectionTitle(name),
mandatory = mandatory,
name = name,
order = ReadCollection.coll_order[name],
})
end
if #item_table > 1 then
table.sort(item_table, function(v1, v2) return v1.order < v2.order end)
end
else
item_table = self.coll_list.item_table
end
local title = T(_("Collections (%1)"), #item_table)
local subtitle
if self.selected_colections then
local selected_nb = util.tableSize(self.selected_colections)
subtitle = self.selected_colections and T(_("Selected collections: %1"), selected_nb)
if do_init and selected_nb > 0 then -- show first collection containing the long-pressed book
for i, item in ipairs(item_table) do
if self.selected_colections[item.name] then
item_number = i
break
end
end
end
end
self.coll_list:switchItemTable(title, item_table, item_number or -1, nil, subtitle)
end
function FileManagerCollection:onCollListChoice(item)
if self._manager.selected_colections then
if item.mandatory == self._manager.checkmark then
self.item_table[item.idx].mandatory = " "
self._manager.selected_colections[item.name] = nil
else
self.item_table[item.idx].mandatory = self._manager.checkmark
self._manager.selected_colections[item.name] = true
end
self._manager:updateCollListItemTable()
else
self._manager:onShowColl(item.name)
end
end
function FileManagerCollection:onCollListHold(item)
if item.name == ReadCollection.default_collection_name -- Favorites non-editable
or self._manager.selected_colections then -- select mode
return
end
local button_dialog
local buttons = {
{
{
text = _("Remove collection"),
callback = function()
UIManager:close(button_dialog)
self._manager:removeCollection(item)
end
},
{
text = _("Rename collection"),
callback = function()
UIManager:close(button_dialog)
self._manager:renameCollection(item)
end
},
},
}
button_dialog = ButtonDialog:new{
title = item.text,
title_align = "center",
buttons = buttons,
}
UIManager:show(button_dialog)
return true
end
function FileManagerCollection:showCollListDialog(caller_callback, no_dialog)
if no_dialog then
caller_callback()
self.coll_list.close_callback(true)
return
end
local button_dialog, buttons
local new_collection_button = {
{
text = _("New collection"),
callback = function()
UIManager:close(button_dialog)
self:addCollection()
end,
},
}
if self.selected_colections then -- select mode
buttons = {
new_collection_button,
{}, -- separator
{
{
text = _("Deselect all"),
callback = function()
UIManager:close(button_dialog)
for name in pairs(self.selected_colections) do
self.selected_colections[name] = nil
end
self:updateCollListItemTable(true)
end,
},
{
text = _("Select all"),
callback = function()
UIManager:close(button_dialog)
for name in pairs(ReadCollection.coll) do
self.selected_colections[name] = true
end
self:updateCollListItemTable(true)
end,
},
},
{
{
text = _("Apply selection"),
callback = function()
UIManager:close(button_dialog)
caller_callback()
self.coll_list.close_callback(true)
end,
},
},
}
else
buttons = {
new_collection_button,
{
{
text = _("Arrange collections"),
callback = function()
UIManager:close(button_dialog)
self:sortCollections()
end,
},
},
}
end
button_dialog = ButtonDialog:new{
buttons = buttons,
}
UIManager:show(button_dialog)
end
function FileManagerCollection:editCollectionName(editCallback, old_name)
local input_dialog
input_dialog = InputDialog:new{
title = _("Enter collection name"),
input = old_name,
input_hint = old_name,
buttons = {{
{
text = _("Cancel"),
id = "close",
callback = function()
UIManager:close(input_dialog)
end,
},
{
text = _("Save"),
callback = function()
local new_name = input_dialog:getInputText()
if new_name == "" or new_name == old_name then return end
if ReadCollection.coll[new_name] then
UIManager:show(InfoMessage:new{
text = T(_("Collection already exists: %1"), new_name),
})
else
UIManager:close(input_dialog)
editCallback(new_name)
end
end,
},
}},
}
UIManager:show(input_dialog)
input_dialog:onShowKeyboard()
end
function FileManagerCollection:addCollection()
local editCallback = function(name)
ReadCollection:addCollection(name)
local mandatory
if self.selected_colections then
self.selected_colections[name] = true
mandatory = self.checkmark
else
mandatory = 0
end
table.insert(self.coll_list.item_table, {
text = name,
mandatory = mandatory,
name = name,
order = ReadCollection.coll_order[name],
})
self:updateCollListItemTable(false, #self.coll_list.item_table) -- show added item
end
self:editCollectionName(editCallback)
end
function FileManagerCollection:renameCollection(item)
local editCallback = function(name)
ReadCollection:renameCollection(item.name, name)
self.coll_list.item_table[item.idx].text = name
self.coll_list.item_table[item.idx].name = name
self:updateCollListItemTable()
end
self:editCollectionName(editCallback, item.name)
end
function FileManagerCollection:removeCollection(item)
UIManager:show(ConfirmBox:new{
text = _("Remove collection?") .. "\n\n" .. item.text,
ok_text = _("Remove"),
ok_callback = function()
ReadCollection:removeCollection(item.name)
table.remove(self.coll_list.item_table, item.idx)
self:updateCollListItemTable()
end,
})
end
function FileManagerCollection:sortCollections()
local sort_widget
sort_widget = SortWidget:new{
title = _("Arrange collections"),
item_table = util.tableDeepCopy(self.coll_list.item_table),
callback = function()
ReadCollection:updateCollectionListOrder(sort_widget.item_table)
self:updateCollListItemTable(true) -- init
end,
}
UIManager:show(sort_widget)
end
-- external
function FileManagerCollection:genAddToCollectionButton(file_or_files, caller_pre_callback, caller_post_callback, button_disabled)
return {
text = _("Add to collection"),
enabled = not button_disabled,
callback = function()
if caller_pre_callback then
caller_pre_callback()
end
local caller_callback = function()
if type(file_or_files) == "string" then
ReadCollection:addRemoveItemMultiple(file_or_files, self.selected_colections)
else -- selected files
ReadCollection:addItemsMultiple(file_or_files, self.selected_colections)
end
if caller_post_callback then
caller_post_callback()
end
end
self:onShowCollList(file_or_files, caller_callback)
end,
}
end
return FileManagerCollection

@ -265,7 +265,7 @@ function FileSearcher:onMenuSelect(item)
table.insert(buttons, {}) -- separator
table.insert(buttons, {
filemanagerutil.genResetSettingsButton(file, close_dialog_callback, is_currently_opened),
filemanagerutil.genAddRemoveFavoritesButton(file, close_dialog_callback),
self.ui.collections:genAddToCollectionButton(file, close_dialog_callback),
})
end
table.insert(buttons, {

@ -6,6 +6,7 @@ local DocSettings = require("docsettings")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local InputDialog = require("ui/widget/inputdialog")
local Menu = require("ui/widget/menu")
local ReadCollection = require("readcollection")
local UIManager = require("ui/uimanager")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local Screen = require("device").screen
@ -69,8 +70,14 @@ function FileManagerHistory:updateItemTable()
local item_table = {}
for _, v in ipairs(require("readhistory").hist) do
if self:isItemMatch(v) then
v.mandatory_dim = (self.is_frozen and v.status == "complete") and true or nil
table.insert(item_table, v)
local item = util.tableDeepCopy(v)
if item.select_enabled and ReadCollection:isFileInCollections(item.file) then
item.mandatory = "" .. item.mandatory
end
if self.is_frozen and item.status == "complete" then
item.mandatory_dim = true
end
table.insert(item_table, item)
end
if self.statuses_fetched then
self.count[v.status] = self.count[v.status] + 1
@ -79,6 +86,8 @@ function FileManagerHistory:updateItemTable()
local subtitle = ""
if self.search_string then
subtitle = T(_("Search results (%1)"), #item_table)
elseif self.selected_colections then
subtitle = T(_("Filtered by collections (%1)"), #item_table)
elseif self.filter ~= "all" then
subtitle = T(_("Status: %1 (%2)"), filter_text[self.filter]:lower(), #item_table)
end
@ -101,6 +110,13 @@ function FileManagerHistory:isItemMatch(item)
end
end
end
if self.selected_colections then
for name in pairs(self.selected_colections) do
if not ReadCollection:isFileInCollection(item.file, name) then
return false
end
end
end
return self.filter == "all" or item.status == self.filter
end
@ -140,6 +156,9 @@ function FileManagerHistory:onMenuHold(item)
self._manager:updateItemTable()
self._manager.files_updated = true -- sidecar folder may be created/deleted
end
local function update_callback()
self._manager:updateItemTable()
end
local is_currently_opened = file == (self.ui.document and self.ui.document.file)
local buttons = {}
@ -168,7 +187,7 @@ function FileManagerHistory:onMenuHold(item)
end
table.insert(buttons, {
filemanagerutil.genResetSettingsButton(doc_settings_or_file, close_dialog_update_callback, is_currently_opened),
filemanagerutil.genAddRemoveFavoritesButton(file, close_dialog_callback, item.dim),
self._manager.ui.collections:genAddToCollectionButton(file, close_dialog_callback, update_callback, item.dim),
})
table.insert(buttons, {
{
@ -251,6 +270,7 @@ function FileManagerHistory:onShowHist(search_info)
self.case_sensitive = search_info.case_sensitive
else
self.search_string = nil
self.selected_colections = nil
end
self.filter = G_reader_settings:readSetting("history_filter", "all")
self.is_frozen = G_reader_settings:isTrue("history_freeze_finished_books")
@ -270,7 +290,7 @@ function FileManagerHistory:onShowHist(search_info)
self.hist_menu = nil
G_reader_settings:saveSetting("history_filter", self.filter)
end
UIManager:show(self.hist_menu)
UIManager:show(self.hist_menu, "flashui")
return true
end
@ -289,6 +309,7 @@ function FileManagerHistory:showHistDialog()
self.filter = filter
if filter == "all" then -- reset all filters
self.search_string = nil
self.selected_colections = nil
end
self:updateItemTable()
end,
@ -304,6 +325,19 @@ function FileManagerHistory:showHistDialog()
genFilterButton("abandoned"),
genFilterButton("complete"),
})
table.insert(buttons, {
{
text = _("Filter by collections"),
callback = function()
UIManager:close(hist_dialog)
local caller_callback = function()
self.selected_colections = self.ui.collections.selected_colections
self:updateItemTable()
end
self.ui.collections:onShowCollList({}, caller_callback, true) -- do not select any, no dialog to apply
end,
},
})
table.insert(buttons, {
{
text = _("Search in filename and book metadata"),

@ -61,6 +61,9 @@ end
function FileManagerMenu:registerKeyEvents()
if Device:hasKeys() then
self.key_events.ShowMenu = { { "Menu" } }
if Device:hasScreenKB() then
self.key_events.OpenLastDoc = { { "ScreenKB", "Back" } }
end
end
end
@ -172,7 +175,8 @@ function FileManagerMenu:setUpdateItemTable()
sub_item_table = {
{
text_func = function()
return T(_("Items per page: %1"), G_reader_settings:readSetting("items_per_page"))
return T(_("Items per page: %1"),
G_reader_settings:readSetting("items_per_page") or FileChooser.items_per_page_default)
end,
help_text = _([[This sets the number of items per page in:
- File browser, history and favorites in 'classic' display mode
@ -180,8 +184,8 @@ function FileManagerMenu:setUpdateItemTable()
- File and folder selection
- Calibre and OPDS browsers/search results]]),
callback = function(touchmenu_instance)
local current_value = G_reader_settings:readSetting("items_per_page")
local default_value = FileChooser.items_per_page_default
local current_value = G_reader_settings:readSetting("items_per_page") or default_value
local widget = SpinWidget:new{
title_text = _("Items per page"),
value = current_value,
@ -204,7 +208,8 @@ function FileManagerMenu:setUpdateItemTable()
end,
callback = function(touchmenu_instance)
local current_value = FileChooser.font_size
local default_value = FileChooser.getItemFontSize(G_reader_settings:readSetting("items_per_page"))
local default_value = FileChooser.getItemFontSize(G_reader_settings:readSetting("items_per_page")
or FileChooser.items_per_page_default)
local widget = SpinWidget:new{
title_text = _("Item font size"),
value = current_value,
@ -452,7 +457,7 @@ To:
if Device:supportsScreensaver() then
self.menu_items.screensaver = {
text = _("Screensaver"),
text = _("Sleep screen"),
sub_item_table = require("ui/elements/screensaver_menu"),
}
end
@ -624,6 +629,30 @@ To:
end,
})
end
if Device:isKobo() and Device:hasColorScreen() then
table.insert(self.menu_items.developer_options.sub_item_table, {
-- We default to a flag (G2) that slightly boosts saturation,
-- but it *is* a destructive process, so we want to allow disabling it.
-- @translators CFA is a technical term for the technology behind eInk's color panels. It stands for Color Film/Filter Array, leave the abbreviation alone ;).
text = _("Disable CFA post-processing"),
checked_func = function()
return G_reader_settings:isTrue("no_cfa_post_processing")
end,
callback = function()
G_reader_settings:flipNilOrFalse("no_cfa_post_processing")
UIManager:askForRestart()
end,
})
end
table.insert(self.menu_items.developer_options.sub_item_table, {
text = _("Anti-alias rounded corners"),
checked_func = function()
return G_reader_settings:nilOrTrue("anti_alias_ui")
end,
callback = function()
G_reader_settings:flipNilOrTrue("anti_alias_ui")
end,
})
--- @note: Currently, only Kobo implements this quirk
if Device:hasEinkScreen() and Device:isKobo() then
table.insert(self.menu_items.developer_options.sub_item_table, {

@ -73,11 +73,18 @@ end
-- Purge doc settings except kept
function filemanagerutil.resetDocumentSettings(file)
local settings_to_keep = {
annotations = true,
annotations_paging = true,
annotations_rolling = true,
bookmarks = true,
bookmarks_paging = true,
bookmarks_rolling = true,
bookmarks_sorted_20220106 = true,
bookmarks_version = true,
cre_dom_version = true,
highlight = true,
highlight_paging = true,
highlight_rolling = true,
highlights_imported = true,
last_page = true,
last_xpointer = true,
@ -234,25 +241,6 @@ function filemanagerutil.genResetSettingsButton(doc_settings_or_file, caller_cal
}
end
function filemanagerutil.genAddRemoveFavoritesButton(file, caller_callback, button_disabled)
local ReadCollection = require("readcollection")
local has_file = ReadCollection:hasFile(file)
return {
text_func = function()
return has_file and _("Remove from favorites") or _("Add to favorites")
end,
enabled = not button_disabled,
callback = function()
caller_callback()
if has_file then
ReadCollection:removeItem(file)
else
ReadCollection:addItem(file)
end
end,
}
end
function filemanagerutil.genShowFolderButton(file, caller_callback, button_disabled)
return {
text = _("Show folder"),

@ -0,0 +1,423 @@
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local logger = require("logger")
local _ = require("gettext")
local T = require("ffi/util").template
local ReaderAnnotation = WidgetContainer:extend{
annotations = nil, -- array sorted by annotation position order, ascending
}
-- build, read, save
function ReaderAnnotation:buildAnnotation(bm, highlights, init)
-- bm: associated single bookmark ; highlights: tables with all highlights
local note = bm.text
if note == "" then
note = nil
end
local chapter = bm.chapter
local hl, pageno = self:getHighlightByDatetime(highlights, bm.datetime)
if init then
if note and self.ui.bookmark:isBookmarkAutoText(bm) then
note = nil
end
if chapter == nil then
chapter = self.ui.toc:getTocTitleByPage(bm.page)
end
pageno = self.ui.paging and bm.page or self.document:getPageFromXPointer(bm.page)
end
if self.ui.paging and bm.pos0 and not bm.pos0.page then
-- old single-page reflow highlights do not have page in position
bm.pos0.page = bm.page
bm.pos1.page = bm.page
end
if not hl then -- page bookmark or orphaned bookmark
hl = {}
if bm.highlighted then -- orphaned bookmark
hl.drawer = self.view.highlight.saved_drawer
hl.color = self.view.highlight.saved_color
if self.ui.paging then
if bm.pos0.page == bm.pos1.page then
hl.pboxes = self.document:getPageBoxesFromPositions(bm.page, bm.pos0, bm.pos1)
else -- multi-page highlight, restore the first box only
hl.pboxes = self.document:getPageBoxesFromPositions(bm.page, bm.pos0, bm.pos0)
end
end
end
end
return { -- annotation
datetime = bm.datetime, -- creation time, not changeable
drawer = hl.drawer, -- highlight drawer
color = hl.color, -- highlight color
text = bm.notes, -- highlighted text, editable
text_edited = hl.edited, -- true if highlighted text has been edited
note = note, -- user's note, editable
chapter = chapter, -- book chapter title
pageno = pageno, -- book page number
page = bm.page, -- highlight location, xPointer or number (pdf)
pos0 = bm.pos0, -- highlight start position, xPointer (== page) or table (pdf)
pos1 = bm.pos1, -- highlight end position, xPointer or table (pdf)
pboxes = hl.pboxes, -- pdf pboxes, used only and changeable by addMarkupAnnotation
ext = hl.ext, -- pdf multi-page highlight
}
end
function ReaderAnnotation:getHighlightByDatetime(highlights, datetime)
for pageno, page_highlights in pairs(highlights) do
for _, highlight in ipairs(page_highlights) do
if highlight.datetime == datetime then
return highlight, pageno
end
end
end
end
function ReaderAnnotation:getAnnotationsFromBookmarksHighlights(bookmarks, highlights, init)
local annotations = {}
for i = #bookmarks, 1, -1 do
table.insert(annotations, self:buildAnnotation(bookmarks[i], highlights, init))
end
if init then
self:sortItems(annotations)
end
return annotations
end
function ReaderAnnotation:onReadSettings(config)
local annotations = config:readSetting("annotations")
if annotations then
-- KOHighlights may set this key when it has merged annotations from different sources:
-- we want to make sure they are updated and sorted
local needs_update = config:isTrue("annotations_externally_modified")
local needs_sort -- if incompatible annotations were built of old highlights/bookmarks
-- Annotation formats in crengine and mupdf are incompatible.
local has_annotations = #annotations > 0
local annotations_type = has_annotations and type(annotations[1].page)
if self.ui.rolling and annotations_type ~= "string" then -- incompatible format loaded, or empty
if has_annotations then -- backup incompatible format if not empty
config:saveSetting("annotations_paging", annotations)
end
-- load compatible format
annotations = config:readSetting("annotations_rolling") or {}
config:delSetting("annotations_rolling")
needs_sort = true
elseif self.ui.paging and annotations_type ~= "number" then
if has_annotations then
config:saveSetting("annotations_rolling", annotations)
end
annotations = config:readSetting("annotations_paging") or {}
config:delSetting("annotations_paging")
needs_sort = true
end
self.annotations = annotations
if needs_update or needs_sort then
if self.ui.rolling then
self.ui:registerPostInitCallback(function()
self:updatedAnnotations(needs_update, needs_sort)
end)
else
self:updatedAnnotations(needs_update, needs_sort)
end
config:delSetting("annotations_externally_modified")
end
else -- first run
if self.ui.rolling then
self.ui:registerPostInitCallback(function()
self:migrateToAnnotations(config)
end)
else
self:migrateToAnnotations(config)
end
end
end
function ReaderAnnotation:migrateToAnnotations(config)
local bookmarks = config:readSetting("bookmarks") or {}
local highlights = config:readSetting("highlight") or {}
if config:hasNot("highlights_imported") then
-- before 2014, saved highlights were not added to bookmarks when they were created.
for page, hls in pairs(highlights) do
for _, hl in ipairs(hls) do
local hl_page = self.ui.paging and page or hl.pos0
-- highlights saved by some old versions don't have pos0 field
-- we just ignore those highlights
if hl_page then
local item = {
datetime = hl.datetime,
highlighted = true,
notes = hl.text,
page = hl_page,
pos0 = hl.pos0,
pos1 = hl.pos1,
}
if self.ui.paging then
item.pos0.page = page
item.pos1.page = page
end
table.insert(bookmarks, item)
end
end
end
end
-- Bookmarks/highlights formats in crengine and mupdf are incompatible.
local has_bookmarks = #bookmarks > 0
local bookmarks_type = has_bookmarks and type(bookmarks[1].page)
if self.ui.rolling then
if bookmarks_type == "string" then -- compatible format loaded, check for incompatible old backup
if config:has("bookmarks_paging") then -- save incompatible old backup
local bookmarks_paging = config:readSetting("bookmarks_paging")
local highlights_paging = config:readSetting("highlight_paging")
local annotations = self:getAnnotationsFromBookmarksHighlights(bookmarks_paging, highlights_paging)
config:saveSetting("annotations_paging", annotations)
config:delSetting("bookmarks_paging")
config:delSetting("highlight_paging")
end
else -- incompatible format loaded, or empty
if has_bookmarks then -- save incompatible format if not empty
local annotations = self:getAnnotationsFromBookmarksHighlights(bookmarks, highlights)
config:saveSetting("annotations_paging", annotations)
end
-- load compatible format
bookmarks = config:readSetting("bookmarks_rolling") or {}
highlights = config:readSetting("highlight_rolling") or {}
config:delSetting("bookmarks_rolling")
config:delSetting("highlight_rolling")
end
else -- self.ui.paging
if bookmarks_type == "number" then
if config:has("bookmarks_rolling") then
local bookmarks_rolling = config:readSetting("bookmarks_rolling")
local highlights_rolling = config:readSetting("highlight_rolling")
local annotations = self:getAnnotationsFromBookmarksHighlights(bookmarks_rolling, highlights_rolling)
config:saveSetting("annotations_rolling", annotations)
config:delSetting("bookmarks_rolling")
config:delSetting("highlight_rolling")
end
else
if has_bookmarks then
local annotations = self:getAnnotationsFromBookmarksHighlights(bookmarks, highlights)
config:saveSetting("annotations_rolling", annotations)
end
bookmarks = config:readSetting("bookmarks_paging") or {}
highlights = config:readSetting("highlight_paging") or {}
config:delSetting("bookmarks_paging")
config:delSetting("highlight_paging")
end
end
self.annotations = self:getAnnotationsFromBookmarksHighlights(bookmarks, highlights, true)
end
function ReaderAnnotation:onDocumentRerendered()
self.needs_update = true
end
function ReaderAnnotation:onCloseDocument()
self:updatePageNumbers()
end
function ReaderAnnotation:onSaveSettings()
self:updatePageNumbers()
self.ui.doc_settings:saveSetting("annotations", self.annotations)
end
-- items handling
function ReaderAnnotation:updatePageNumbers()
if self.needs_update and self.ui.rolling then -- triggered by ReaderRolling on document layout change
for _, item in ipairs(self.annotations) do
item.pageno = self.document:getPageFromXPointer(item.page)
end
end
self.needs_update = nil
end
function ReaderAnnotation:sortItems(items)
if #items > 1 then
local sort_func = self.ui.rolling and function(a, b) return self:isItemInPositionOrderRolling(a, b) end
or function(a, b) return self:isItemInPositionOrderPaging(a, b) end
table.sort(items, sort_func)
end
end
function ReaderAnnotation:updatedAnnotations(needs_update, needs_sort)
if needs_update then
self.needs_update = true
self:updatePageNumbers()
needs_sort = true
end
if needs_sort then
self:sortItems(self.annotations)
end
end
function ReaderAnnotation:updateItemByXPointer(item)
-- called by ReaderRolling:checkXPointersAndProposeDOMVersionUpgrade()
local chapter = self.ui.toc:getTocTitleByPage(item.page)
if chapter == "" then
chapter = nil
end
if not item.drawer then -- page bookmark
item.text = chapter and T(_("in %1"), chapter) or nil
end
item.chapter = chapter
item.pageno = self.document:getPageFromXPointer(item.page)
end
function ReaderAnnotation:isItemInPositionOrderRolling(a, b)
local a_page = self.document:getPageFromXPointer(a.page)
local b_page = self.document:getPageFromXPointer(b.page)
if a_page == b_page then -- both items in the same page
if a.drawer and b.drawer then -- both items are highlights, compare positions
local compare_xp = self.document:compareXPointers(a.page, b.page)
if compare_xp then
if compare_xp == 0 then -- both highlights with the same start, compare ends
compare_xp = self.document:compareXPointers(a.pos1, b.pos1)
if compare_xp then
return compare_xp > 0
end
logger.warn("Invalid xpointer in highlight:", a.pos1, b.pos1)
return true
end
return compare_xp > 0
end
-- if compare_xp is nil, some xpointer is invalid and "a" will be sorted first to page 1
logger.warn("Invalid xpointer in highlight:", a.page, b.page)
return true
end
return not a.drawer -- have page bookmarks before highlights
end
return a_page < b_page
end
function ReaderAnnotation:isItemInPositionOrderPaging(a, b)
if a.page == b.page then -- both items in the same page
if a.drawer and b.drawer then -- both items are highlights, compare positions
local is_reflow = self.document.configurable.text_wrap -- save reflow mode
self.document.configurable.text_wrap = 0 -- native positions
-- sort start and end positions of each highlight
local a_start, a_end, b_start, b_end, result
if self.document:comparePositions(a.pos0, a.pos1) > 0 then
a_start, a_end = a.pos0, a.pos1
else
a_start, a_end = a.pos1, a.pos0
end
if self.document:comparePositions(b.pos0, b.pos1) > 0 then
b_start, b_end = b.pos0, b.pos1
else
b_start, b_end = b.pos1, b.pos0
end
-- compare start positions
local compare_pos = self.document:comparePositions(a_start, b_start)
if compare_pos == 0 then -- both highlights with the same start, compare ends
result = self.document:comparePositions(a_end, b_end) > 0
else
result = compare_pos > 0
end
self.document.configurable.text_wrap = is_reflow -- restore reflow mode
return result
end
return not a.drawer -- have page bookmarks before highlights
end
return a.page < b.page
end
function ReaderAnnotation:getItemIndex(item, no_binary)
local doesMatch
if item.datetime then
doesMatch = function(a, b)
return a.datetime == b.datetime
end
else
if self.ui.rolling then
doesMatch = function(a, b)
if a.text ~= b.text or a.pos0 ~= b.pos0 or a.pos1 ~= b.pos1 then
return false
end
return true
end
else
doesMatch = function(a, b)
if a.text ~= b.text or a.pos0.page ~= b.pos0.page
or a.pos0.x ~= b.pos0.x or a.pos1.x ~= b.pos1.x
or a.pos0.y ~= b.pos0.y or a.pos1.y ~= b.pos1.y then
return false
end
return true
end
end
end
if not no_binary then
local isInOrder = self.ui.rolling and self.isItemInPositionOrderRolling or self.isItemInPositionOrderPaging
local _start, _end, _middle = 1, #self.annotations
while _start <= _end do
_middle = bit.rshift(_start + _end, 1)
local v = self.annotations[_middle]
if doesMatch(item, v) then
return _middle
elseif isInOrder(self, item, v) then
_end = _middle - 1
else
_start = _middle + 1
end
end
end
for i, v in ipairs(self.annotations) do
if doesMatch(item, v) then
return i
end
end
end
function ReaderAnnotation:getInsertionIndex(item)
local isInOrder = self.ui.rolling and self.isItemInPositionOrderRolling or self.isItemInPositionOrderPaging
local _start, _end, _middle, direction = 1, #self.annotations, 1, 0
while _start <= _end do
_middle = bit.rshift(_start + _end, 1)
if isInOrder(self, item, self.annotations[_middle]) then
_end, direction = _middle - 1, 0
else
_start, direction = _middle + 1, 1
end
end
return _middle + direction
end
function ReaderAnnotation:addItem(item)
item.datetime = os.date("%Y-%m-%d %H:%M:%S")
item.pageno = self.ui.paging and item.page or self.document:getPageFromXPointer(item.page)
local index = self:getInsertionIndex(item)
table.insert(self.annotations, index, item)
return index
end
-- info
function ReaderAnnotation:hasAnnotations()
return #self.annotations > 0
end
function ReaderAnnotation:getNumberOfAnnotations()
return #self.annotations
end
function ReaderAnnotation:getNumberOfHighlightsAndNotes() -- for Statistics plugin
local highlights = 0
local notes = 0
for _, item in ipairs(self.annotations) do
if item.drawer then
if item.note then
notes = notes + 1
else
highlights = highlights + 1
end
end
end
return highlights, notes
end
return ReaderAnnotation

File diff suppressed because it is too large Load Diff

@ -41,6 +41,11 @@ function ReaderCoptListener:onReadSettings(config)
self.document._document:setIntProperty("window.status.battery.percent", self.battery_percent)
self.document._document:setIntProperty("window.status.pos.percent", self.reading_percent)
-- We will build the top status bar page info string ourselves,
-- if we have to display any chunk of it
self.page_info_override = self.page_number == 1 or self.page_count == 1 or self.reading_percent == 1
self.document:setPageInfoOverride("") -- an empty string lets crengine display its own page info
self:onTimeFormatChanged()
-- Enable or disable crengine header status line (note that for crengine, 0=header enabled, 1=header disabled)
@ -76,6 +81,80 @@ function ReaderCoptListener:onReaderReady()
end
end
function ReaderCoptListener:updatePageInfoOverride(pageno)
if not (self.document.configurable.status_line == 0 and self.view.view_mode == "page" and self.page_info_override) then
return
end
-- There are a few cases where we may not be updated on change, at least:
-- - when toggling ReaderPageMap's "Use reference page numbers"
-- - when changing footer's nb of digits after decimal point
-- but we will update on next page turn. Let's not bother.
local page_pre = ""
local page_number = pageno
local page_sep = " / "
local page_count = self.ui.document:getPageCount()
local page_post = ""
local percentage = page_number / page_count
local percentage_pre = ""
local percentage_post = ""
-- Let's use the same setting for nb of digits after decimal point as configured for the footer
local percentage_digits = self.ui.view.footer.settings.progress_pct_format
local percentage_fmt = "%." .. percentage_digits .. "f%%"
-- We want the same output as with ReaderFooter's page_progress() and percentage()
-- but here each item (page number, page counte, percentage) is individually toggable,
-- so try to get something that make sense when not all are enabled
if self.ui.pagemap and self.ui.pagemap:wantsPageLabels() then
-- These become strings here
page_number = self.ui.pagemap:getCurrentPageLabel(true)
page_count = self.ui.pagemap:getLastPageLabel(true)
elseif self.ui.document:hasHiddenFlows() then
local flow = self.ui.document:getPageFlow(pageno)
page_number = tostring(self.ui.document:getPageNumberInFlow(pageno))
page_count = tostring(self.ui.document:getTotalPagesInFlow(flow))
percentage = page_number / page_count
if flow == 0 then
page_sep = " // "
else
page_pre = "["
page_post = "]"..tostring(flow)
percentage_pre = "["
percentage_post = "]"
end
end
local page_info = ""
if self.page_number or self.page_count then
page_info = page_info .. page_pre
if self.page_number then
page_info = page_info .. page_number
if self.page_count then
page_info = page_info .. page_sep
end
end
if self.page_count then
page_info = page_info .. page_count
end
page_info = page_info .. page_post
if self.reading_percent then
page_info = page_info .. " " -- (double space as done by crengine's own drawing)
end
end
if self.reading_percent then
page_info = page_info .. percentage_pre .. percentage_fmt:format(percentage*100) .. percentage_post
end
self.document:setPageInfoOverride(page_info)
end
function ReaderCoptListener:onPageUpdate(pageno)
self:updatePageInfoOverride(pageno)
end
function ReaderCoptListener:onPosUpdate(pos, pageno)
self:updatePageInfoOverride(pageno)
end
function ReaderCoptListener:onBookMetadataChanged(prop_updated)
-- custom metadata support for alt status bar and cre synthetic cover
local prop_key = prop_updated and prop_updated.metadata_key_updated
@ -191,6 +270,8 @@ ReaderCoptListener.onSuspend = ReaderCoptListener.unscheduleHeaderRefresh
function ReaderCoptListener:setAndSave(setting, property, value)
self.document._document:setIntProperty(property, value)
G_reader_settings:saveSetting(setting, value)
self.page_info_override = self.page_number == 1 or self.page_count == 1 or self.reading_percent == 1
self.document:setPageInfoOverride("")
-- Have crengine redraw it (even if hidden by the menu at this time)
self.ui.rolling:updateBatteryState()
self:updateHeader()
@ -211,7 +292,7 @@ function ReaderCoptListener:getAltStatusBarMenu()
separator = true,
sub_item_table = {
{
text = _("About alternate status bar"),
text = _("About alt status bar"),
keep_menu_open = true,
callback = function()
UIManager:show(InfoMessage:new{
@ -294,15 +375,18 @@ function ReaderCoptListener:getAltStatusBarMenu()
},
{
text_func = function()
local status = _("off")
local status = _("Battery status")
if self.battery == 1 then
if self.battery_percent == 1 then
status = _("percentage")
status = _("Battery status: percentage")
else
status = _("icon")
status = _("Battery status: icon")
end
end
return T(_("Battery status: %1"), status)
return status
end,
checked_func = function()
return self.battery == 1
end,
sub_item_table = {
{

@ -21,8 +21,6 @@ function ReaderCropping:onPageCrop(mode)
-- backup original zoom mode as cropping use "page" zoom mode
self.orig_zoom_mode = self.view.zoom_mode
if mode == "auto" then
--- @fixme: This is weird. "auto" crop happens to be the default, yet the default zoom mode/genus is "page", not "content".
--- This effectively yields different results whether auto is enabled by default, or toggled at runtime...
if self.document.configurable.text_wrap ~= 1 then
self:setCropZoomMode(true)
end

@ -424,7 +424,7 @@ function ReaderDictionary:addToMainMenu(menu_items)
end
end
function ReaderDictionary:onLookupWord(word, is_sane, boxes, highlight, link, tweak_buttons_func)
function ReaderDictionary:onLookupWord(word, is_sane, boxes, highlight, link)
logger.dbg("dict lookup word:", word, boxes)
-- escape quotes and other funny characters in word
word = self:cleanSelection(word, is_sane)
@ -440,7 +440,7 @@ function ReaderDictionary:onLookupWord(word, is_sane, boxes, highlight, link, tw
-- Wrapped through Trapper, as we may be using Trapper:dismissablePopen() in it
Trapper:wrap(function()
self:stardictLookup(word, self.enabled_dict_names, not disable_fuzzy_search, boxes, link, tweak_buttons_func)
self:stardictLookup(word, self.enabled_dict_names, not disable_fuzzy_search, boxes, link)
end)
return true
end
@ -932,7 +932,7 @@ function ReaderDictionary:startSdcv(word, dict_names, fuzzy_search)
return results
end
function ReaderDictionary:stardictLookup(word, dict_names, fuzzy_search, boxes, link, tweak_buttons_func)
function ReaderDictionary:stardictLookup(word, dict_names, fuzzy_search, boxes, link)
if word == "" then
return
end
@ -992,16 +992,15 @@ function ReaderDictionary:stardictLookup(word, dict_names, fuzzy_search, boxes,
return
end
self:showDict(word, tidyMarkup(results), boxes, link, tweak_buttons_func)
self:showDict(word, tidyMarkup(results), boxes, link)
end
function ReaderDictionary:showDict(word, results, boxes, link, tweak_buttons_func)
function ReaderDictionary:showDict(word, results, boxes, link)
if results and results[1] then
logger.dbg("showing quick lookup window", #DictQuickLookup.window_list+1, ":", word, results)
self.dict_window = DictQuickLookup:new{
ui = self.ui,
highlight = self.highlight,
tweak_buttons_func = tweak_buttons_func,
dialog = self.dialog,
-- original lookup word
word = word,
@ -1114,15 +1113,24 @@ function ReaderDictionary:downloadDictionary(dict, download_location, continue)
--logger.dbg(headers)
file_size = headers and headers["content-length"]
UIManager:show(ConfirmBox:new{
text = T(_("Dictionary filesize is %1 (%2 bytes). Continue with download?"), util.getFriendlySize(file_size), util.getFormattedSize(file_size)),
ok_text = _("Download"),
ok_callback = function()
-- call ourselves with continue = true
self:downloadDictionary(dict, download_location, true)
end,
})
return
if file_size then
UIManager:show(ConfirmBox:new{
text = T(_("Dictionary filesize is %1 (%2 bytes). Continue with download?"), util.getFriendlySize(file_size), util.getFormattedSize(file_size)),
ok_text = _("Download"),
ok_callback = function()
-- call ourselves with continue = true
self:downloadDictionary(dict, download_location, true)
end,
})
return
else
logger.dbg("ReaderDictionary: Request failed; response headers:", headers)
UIManager:show(InfoMessage:new{
text = _("Failed to fetch dictionary. Are you online?"),
--timeout = 3,
})
return false
end
else
UIManager:nextTick(function()
UIManager:show(InfoMessage:new{

@ -1,5 +1,4 @@
local BD = require("ui/bidi")
local CenterContainer = require("ui/widget/container/centercontainer")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local Event = require("ui/event")
@ -8,7 +7,6 @@ local FontList = require("fontlist")
local InfoMessage = require("ui/widget/infomessage")
local Input = Device.input
local InputContainer = require("ui/widget/container/inputcontainer")
local Menu = require("ui/widget/menu")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
local Notification = require("ui/widget/notification")
local Screen = require("device").screen
@ -142,20 +140,19 @@ function ReaderFont:onGesture() end
function ReaderFont:registerKeyEvents()
if Device:hasKeyboard() then
-- add shortcut for keyboard
self.key_events = {
ShowFontMenu = { { "F" } },
IncreaseSize = {
if not (Device:hasScreenKB() or Device:hasSymKey()) then
-- add shortcut for keyboard
self.key_events.IncreaseSize = {
{ "Shift", Input.group.PgFwd },
event = "ChangeSize",
args = 0.5
},
DecreaseSize = {
}
self.key_events.DecreaseSize = {
{ "Shift", Input.group.PgBack },
event = "ChangeSize",
args = -0.5
},
}
}
end
end
end
@ -196,34 +193,6 @@ function ReaderFont:onReadSettings(config)
end)
end
function ReaderFont:onShowFontMenu()
-- build menu widget
local main_menu = Menu:new{
title = self.font_menu_title,
item_table = self.face_table,
width = Screen:getWidth() - 100,
height = math.floor(Screen:getHeight() * 0.5),
single_line = true,
items_per_page = 8,
items_font_size = Menu.getItemFontSize(8),
}
-- build container
local menu_container = CenterContainer:new{
dimen = Screen:getSize(),
main_menu,
}
main_menu.close_callback = function()
UIManager:close(menu_container)
end
-- show menu
main_menu.show_parent = menu_container
UIManager:show(menu_container)
return true
end
--[[
UpdatePos event is used to tell ReaderRolling to update pos.
--]]

File diff suppressed because it is too large Load Diff

@ -181,4 +181,28 @@ function ReaderGoto:onGoToEnd()
return true
end
function ReaderGoto:onGoToRandomPage()
local page_count = self.document:getPageCount()
if page_count == 1 then return true end
local current_page = self.ui:getCurrentPage()
if self.pages_pool == nil then
self.pages_pool = {}
end
if #self.pages_pool == 0 or (#self.pages_pool == 1 and self.pages_pool[1] == current_page) then
for i = 1, page_count do
self.pages_pool[i] = i
end
end
while true do
local random_page_idx = math.random(1, #self.pages_pool)
local random_page = self.pages_pool[random_page_idx]
if random_page ~= current_page then
table.remove(self.pages_pool, random_page_idx)
self.ui.link:addCurrentLocationToStack()
self.ui:handleEvent(Event:new("GotoPage", random_page))
return true
end
end
end
return ReaderGoto

@ -1,4 +1,5 @@
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local Event = require("ui/event")
local InfoMessage = require("ui/widget/infomessage")
local InputDialog = require("ui/widget/inputdialog")
@ -119,6 +120,10 @@ function ReaderHandMade:onToggleHandmadeFlows()
end
function ReaderHandMade:addToMainMenu(menu_items)
-- As it's currently impossible to create custom hidden flows on non-touch, and really impractical to create a custom toc, it's better hide these features completely for now.
if not Device:isTouchDevice() then
return
end
menu_items.handmade_toc = {
text = _("Custom table of contents") .. " " .. self.custom_toc_symbol,
checked_func = function() return self.toc_enabled end,

File diff suppressed because it is too large Load Diff

@ -3,7 +3,7 @@ ReaderLink is an abstraction for document-specific link interfaces.
]]
local BD = require("ui/bidi")
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
local ButtonDialog = require("ui/widget/buttondialog")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local DocumentRegistry = require("document/documentregistry")
@ -67,6 +67,7 @@ local ReaderLink = InputContainer:extend{
location_stack = nil, -- table, per-instance
forward_location_stack = nil, -- table, per-instance
_external_link_buttons = nil,
handledSchemes = {"http", "https"},
}
function ReaderLink:init()
@ -118,7 +119,7 @@ function ReaderLink:init()
end)
if G_reader_settings:isTrue("opening_page_location_stack") then
-- Add location at book opening to stack
self.ui:registerPostReadyCallback(function()
self.ui:registerPostReaderReadyCallback(function()
self:addCurrentLocationToStack()
end)
end
@ -142,6 +143,7 @@ function ReaderLink:init()
return {
text = _("Copy"),
callback = function()
Device.input.setClipboardText(link_url)
UIManager:close(this.external_link_dialog)
end,
}
@ -224,10 +226,25 @@ function ReaderLink:init()
end
end
function ReaderLink:registerScheme(scheme)
table.insert(self.handledSchemes, scheme)
end
function ReaderLink:onGesture() end
function ReaderLink:registerKeyEvents()
if Device:hasKeys() then
if Device:hasScreenKB() or Device:hasSymKey() then
self.key_events.GotoSelectedPageLink = { { "Press" }, event = "GotoSelectedPageLink" }
if Device:hasKeyboard() then
self.key_events.AddCurrentLocationToStackNonTouch = { { "Shift", "Press" } }
self.key_events.SelectNextPageLink = { { "Shift", "LPgFwd" }, event = "SelectNextPageLink" }
self.key_events.SelectPrevPageLink = { { "Shift", "LPgBack" }, event = "SelectPrevPageLink" }
else
self.key_events.AddCurrentLocationToStackNonTouch = { { "ScreenKB", "Press" } }
self.key_events.SelectNextPageLink = { { "ScreenKB", "LPgFwd" }, event = "SelectNextPageLink" }
self.key_events.SelectPrevPageLink = { { "ScreenKB", "LPgBack" }, event = "SelectPrevPageLink" }
end
elseif Device:hasKeys() then
self.key_events = {
SelectNextPageLink = {
{ "Tab" },
@ -235,7 +252,6 @@ function ReaderLink:registerKeyEvents()
},
SelectPrevPageLink = {
{ "Shift", "Tab" },
{ "Sym", "Tab" }, -- Shift or Sym + Tab
event = "SelectPrevPageLink",
},
GotoSelectedPageLink = {
@ -702,6 +718,13 @@ function ReaderLink:onAddCurrentLocationToStack(show_notification)
if show_notification then
Notification:notify(_("Current location added to history."))
end
return true
end
function ReaderLink:onAddCurrentLocationToStackNonTouch()
self:addCurrentLocationToStack()
Notification:notify(_("Current location added to history."), Notification.SOURCE_ALWAYS_SHOW)
return true
end
-- Remember current location so we can go back to it
@ -711,6 +734,10 @@ function ReaderLink:addCurrentLocationToStack(loc)
table.insert(self.location_stack, location)
end
function ReaderLink:popFromLocationStack()
return table.remove(self.location_stack)
end
function ReaderLink:onClearLocationStack(show_notification)
self.location_stack = {}
self:onClearForwardLocationStack()
@ -807,8 +834,9 @@ function ReaderLink:onGotoLink(link, neglect_current_location, allow_footnote_po
end
logger.dbg("ReaderLink:onGotoLink: External link:", link_url)
local is_http_link = link_url:find("^https?://") ~= nil
if is_http_link and self:onGoToExternalLink(link_url) then
local scheme = link_url:match("^(%w+)://")
local is_handled_external_link = scheme and util.arrayContains(self.handledSchemes, scheme)
if is_handled_external_link and self:onGoToExternalLink(link_url) then
return true
end
@ -857,7 +885,7 @@ end
function ReaderLink:onGoToExternalLink(link_url)
local buttons, title = self:getButtonsForExternalLinkDialog(link_url)
self.external_link_dialog = ButtonDialogTitle:new{
self.external_link_dialog = ButtonDialog:new{
title = title,
buttons = buttons,
}

@ -254,7 +254,7 @@ function ReaderMenu:setUpdateItemTable()
if Device:supportsScreensaver() then
local ss_book_settings = {
text = _("Exclude this book's content and cover from screensaver"),
text = _("Do not show this book cover on sleep screen"),
enabled_func = function()
if self.ui and self.ui.document then
local screensaverType = G_reader_settings:readSetting("screensaver_type")
@ -285,7 +285,7 @@ function ReaderMenu:setUpdateItemTable()
end
table.insert(screensaver_sub_item_table, ss_book_settings)
self.menu_items.screensaver = {
text = _("Screensaver"),
text = _("Sleep screen"),
sub_item_table = screensaver_sub_item_table,
}
end

@ -280,8 +280,11 @@ function ReaderPageMap:getCurrentPageLabel(clean_label)
-- For consistency, getPageMapCurrentPageLabel() returns the last page
-- label shown in the view if there are more than one (or the previous
-- one if there is none).
local label = self.ui.document:getPageMapCurrentPageLabel()
return clean_label and self:cleanPageLabel(label) or label
local label, idx, count = self.ui.document:getPageMapCurrentPageLabel()
if clean_label then
label = self:cleanPageLabel(label)
end
return label, idx, count
end
function ReaderPageMap:getFirstPageLabel(clean_label)

@ -51,7 +51,28 @@ end
function ReaderPaging:onGesture() end
function ReaderPaging:registerKeyEvents()
if Device:hasKeys() then
if Device:hasDPad() and Device:useDPadAsActionKeys() then
self.key_events.GotoNextPos = {
{ { "RPgFwd", "LPgFwd" } },
event = "GotoPosRel",
args = 1,
}
self.key_events.GotoPrevPos = {
{ { "RPgBack", "LPgBack" } },
event = "GotoPosRel",
args = -1,
}
self.key_events.GotoNextChapter = {
{ "Right" },
event = "GotoNextChapter",
args = 1,
}
self.key_events.GotoPrevChapter = {
{ "Left" },
event = "GotoPrevChapter",
args = -1,
}
elseif Device:hasKeys() then
self.key_events.GotoNextPage = {
{ { "RPgFwd", "LPgFwd", not Device:hasFewKeys() and "Right" } },
event = "GotoViewRel",

@ -100,7 +100,7 @@ function ReaderRolling:init()
self.valid_cache_rendering_hash = self.ui.document:getDocumentRenderingHash(false)
end
end)
table.insert(self.ui.postReaderCallback, function()
table.insert(self.ui.postReaderReadyCallback, function()
self:updatePos()
-- Disable crengine internal history, with required redraw
self.ui.document:enableInternalHistory(false)
@ -116,7 +116,30 @@ end
function ReaderRolling:onGesture() end
function ReaderRolling:registerKeyEvents()
if Device:hasKeys() then
if Device:hasScreenKB() or Device:hasSymKey() then
self.key_events.GotoNextView = {
{ { "RPgFwd", "LPgFwd" } },
event = "GotoViewRel",
args = 1,
}
self.key_events.GotoPrevView = {
{ { "RPgBack", "LPgBack" } },
event = "GotoViewRel",
args = -1,
}
if Device:hasKeyboard() then
self.key_events.MoveUp = {
{ "Shift", "RPgBack" },
event = "Panning",
args = {0, -1},
}
self.key_events.MoveDown = {
{ "Shift", "RPgFwd" },
event = "Panning",
args = {0, 1},
}
end
elseif Device:hasKeys() then
self.key_events.GotoNextView = {
{ { "RPgFwd", "LPgFwd", "Right" } },
event = "GotoViewRel",
@ -128,7 +151,18 @@ function ReaderRolling:registerKeyEvents()
args = -1,
}
end
if Device:hasDPad() then
if Device:hasDPad() and Device:useDPadAsActionKeys() then
self.key_events.GotoNextChapter = {
{ "Right" },
event = "GotoNextChapter",
args = 1,
}
self.key_events.GotoPrevChapter = {
{ "Left" },
event = "GotoPrevChapter",
args = -1,
}
elseif Device:hasDPad() then
self.key_events.MoveUp = {
{ "Up" },
event = "Panning",
@ -140,6 +174,18 @@ function ReaderRolling:registerKeyEvents()
args = {0, 1},
}
end
if Device:hasScreenKB() then
self.key_events.MoveUp = {
{ "ScreenKB", "RPgBack" },
event = "Panning",
args = {0, -1},
}
self.key_events.MoveDown = {
{ "ScreenKB", "RPgFwd" },
event = "Panning",
args = {0, 1},
}
end
if Device:hasKeyboard() then
self.key_events.GotoFirst = {
{ "1" },
@ -234,7 +280,7 @@ function ReaderRolling:onReadSettings(config)
-- And check if we can migrate to a newest DOM version after
-- the book is loaded (unless the user told us not to).
if config:nilOrFalse("cre_keep_old_dom_version") then
self.ui:registerPostReadyCallback(function()
self.ui:registerPostReaderReadyCallback(function()
self:checkXPointersAndProposeDOMVersionUpgrade()
end)
end
@ -1029,9 +1075,9 @@ function ReaderRolling:onUpdatePos(force)
if self.batched_update_count > 0 then
return
end
if self.ui.postReaderCallback ~= nil then -- ReaderUI:init() not yet done
if self.ui.postReaderReadyCallback ~= nil then -- ReaderUI:init() not yet done
-- Don't schedule any updatePos as long as ReaderUI:init() is
-- not finished (one will be called in the ui.postReaderCallback
-- not finished (one will be called in the ui.postReaderReadyCallback
-- we have set above) to avoid multiple refreshes.
return true
end
@ -1129,7 +1175,7 @@ function ReaderRolling:onRedrawCurrentView()
end
function ReaderRolling:onSetDimensions(dimen)
if self.ui.postReaderCallback ~= nil then
if self.ui.postReaderReadyCallback ~= nil then
-- ReaderUI:init() not yet done: just set document dimensions
self.ui.document:setViewDimen(Screen:getSize())
-- (what's done in the following else is done elsewhere by
@ -1445,25 +1491,12 @@ function ReaderRolling:checkXPointersAndProposeDOMVersionUpgrade()
local applyFuncToXPointersSlots = function(func)
-- Last position
func(self, "xpointer", "last position in book")
-- Bookmarks
if self.ui.bookmark and self.ui.bookmark.bookmarks and #self.ui.bookmark.bookmarks > 0 then
-- Annotations
if self.ui.annotation and self.ui.annotation.annotations and #self.ui.annotation.annotations > 0 then
local slots = { "page", "pos0", "pos1" }
for _, bookmark in ipairs(self.ui.bookmark.bookmarks) do
for _, item in ipairs(self.ui.annotation.annotations) do
for _, slot in ipairs(slots) do
func(bookmark, slot, bookmark.notes or "bookmark")
end
end
end
-- Highlights
if self.view.highlight and self.view.highlight.saved then
local slots = { "pos0", "pos1" }
for page, items in pairs(self.view.highlight.saved) do
if items and #items > 0 then
for _, highlight in ipairs(items) do
for _, slot in ipairs(slots) do
func(highlight, slot, highlight.text or "highlight")
end
end
func(item, slot, item.text or "annotation")
end
end
end
@ -1509,6 +1542,9 @@ function ReaderRolling:checkXPointersAndProposeDOMVersionUpgrade()
local new_xp = normalized_xpointers[xp]
if new_xp then
obj[slot] = new_xp
if slot == "page" then
self.ui.annotation:updateItemByXPointer(obj)
end
else
-- Let lost/not-found XPointer be. There is a small chance that
-- it will be found (it it was made before the boxing code moved

@ -83,6 +83,16 @@ function ReaderSearch:addToMainMenu(menu_items)
menu_items.fulltext_search_settings = {
text = _("Fulltext search settings"),
sub_item_table = {
{
text = _("Show all results on text selection"),
help_text = _("When invoked after text selection, show a list with all results instead of highlighting matches in book pages."),
checked_func = function()
return G_reader_settings:isTrue("fulltext_search_find_all")
end,
callback = function()
G_reader_settings:flipNilOrFalse("fulltext_search_find_all")
end,
},
{
text_func = function()
return T(_("Words in context: %1"), self.findall_nb_context_words)
@ -142,19 +152,36 @@ function ReaderSearch:addToMainMenu(menu_items)
}
end
-- if reverse ~= 0 search backwards
function ReaderSearch:searchCallback(reverse)
local search_text = self.input_dialog:getInputText()
if search_text == "" then return end
-- search_text comes from our keyboard, and may contain multiple diacritics ordered
-- in any order: we'd rather have them normalized, and expect the book content to
-- be proper and normalized text.
function ReaderSearch:searchText(text) -- from highlight dialog
if G_reader_settings:isTrue("fulltext_search_find_all") then
self.ui.highlight:clear()
self:searchCallback(nil, text)
else
self:searchCallback(0, text) -- forward
end
end
-- if reverse == 1 search backwards
function ReaderSearch:searchCallback(reverse, text)
local search_text = text or self.input_dialog:getInputText()
if search_text == nil or search_text == "" then return end
self.ui.doc_settings:saveSetting("fulltext_search_last_search_text", search_text)
self.last_search_text = search_text -- if shown again, show it as it has been inputted
search_text = Utf8Proc.normalize_NFC(search_text)
self.use_regex = self.check_button_regex.checked
self.case_insensitive = not self.check_button_case.checked
local regex_error = self.use_regex and self.ui.document:checkRegex(search_text)
self.last_search_text = search_text
local regex_error
if text then -- from highlight dialog
self.use_regex = false
self.case_insensitive = true
else -- from input dialog
-- search_text comes from our keyboard, and may contain multiple diacritics ordered
-- in any order: we'd rather have them normalized, and expect the book content to
-- be proper and normalized text.
search_text = Utf8Proc.normalize_NFC(search_text)
self.use_regex = self.check_button_regex.checked
self.case_insensitive = not self.check_button_case.checked
regex_error = self.use_regex and self.ui.document:checkRegex(search_text)
end
if self.use_regex and regex_error ~= 0 then
logger.dbg("ReaderSearch: regex error", regex_error, SRELL_ERROR_CODES[regex_error])
local error_message
@ -167,6 +194,7 @@ function ReaderSearch:searchCallback(reverse)
else
UIManager:close(self.input_dialog)
if reverse then
self.last_search_hash = nil
self:onShowSearchDialog(search_text, reverse, self.use_regex, self.case_insensitive)
else
local Trapper = require("ui/trapper")
@ -261,6 +289,9 @@ function ReaderSearch:onShowSearchDialog(text, direction, regex, case_insensitiv
local res = search_func(self, search_term, param, regex, case_insensitive)
if res then
if self.ui.paging then
if not current_page then -- initial search
current_page = self.ui.paging.current_page
end
no_results = false
self.ui.link:onGotoLink({page = res.page - 1}, neglect_current_location)
self.view.highlight.temp[res.page] = res
@ -329,8 +360,24 @@ function ReaderSearch:onShowSearchDialog(text, direction, regex, case_insensitiv
self.ui.link:onGotoLink({xpointer=valid_link}, neglect_current_location)
end
end
-- Don't add result pages to location ("Go back") stack
neglect_current_location = true
if not neglect_current_location then
-- Initial search: onGotoLink() has added the current page to the location stack,
-- and we don't want this to be done when showing further pages with results.
-- But if this initial search is showing results on the current page, we don't want
-- the original page added: we will do it when we jump to a different page.
-- For now, only do this with CreDocument. With PDF, whether in single page mode or
-- in scroll mode, the view can scroll a bit when showing results, and we want to
-- allow "go back" to restore the original viewport.
if self.ui.rolling and self.view.view_mode == "page" then
if current_page == (self.ui.rolling and self.ui.document:getCurrentPage() or self.ui.paging.current_page) then
self.ui.link:popFromLocationStack()
neglect_current_location = false
else
-- We won't add further result pages to the location stack ("Go back").
neglect_current_location = true
end
end
end
end
if no_results then
local notification_text
@ -392,7 +439,6 @@ function ReaderSearch:onShowSearchDialog(text, direction, regex, case_insensitiv
icon_height = Screen:scaleBySize(DGENERIC_ICON_SIZE * 0.8),
callback = function()
self.search_dialog:onClose()
self.last_search_text = text
self:onShowFulltextSearchInput()
end,
},
@ -500,7 +546,7 @@ function ReaderSearch:searchNext(pattern, direction, regex, case_insensitive)
end
function ReaderSearch:findAllText(search_text)
local last_search_hash = self.last_search_text .. tostring(self.case_insensitive) .. tostring(self.use_regex)
local last_search_hash = (self.last_search_text or "") .. tostring(self.case_insensitive) .. tostring(self.use_regex)
local not_cached = self.last_search_hash ~= last_search_hash
if not_cached then
local Trapper = require("ui/trapper")
@ -525,7 +571,7 @@ function ReaderSearch:findAllText(search_text)
end
function ReaderSearch:onShowFindAllResults(not_cached)
if not not_cached and self.findall_results == nil then
if not self.last_search_hash or (not not_cached and self.findall_results == nil) then
-- no cached results, show input dialog
self:onShowFulltextSearchInput()
return
@ -546,9 +592,15 @@ function ReaderSearch:onShowFindAllResults(not_cached)
local text = TextBoxWidget.PTF_BOLD_START .. word .. TextBoxWidget.PTF_BOLD_END
-- append context before and after the word
if item.prev_text then
if not item.prev_text:find("%s$") then
text = " " .. text
end
text = item.prev_text .. text
end
if item.next_text then
if not item.next_text:find("^[%s%p]") then
text = text .. " "
end
text = text .. item.next_text
end
text = TextBoxWidget.PTF_HEADER .. text -- enable handling of our bold tags

@ -219,6 +219,7 @@ end
-- Otherwise we change status from reading/abandoned to complete or from complete to reading.
function ReaderStatus:onMarkBook(mark_read)
self.summary.status = (not mark_read and self.summary.status == "complete") and "reading" or "complete"
self.summary.modified = os.date("%Y-%m-%d", os.time())
-- If History is called over Reader, it will read the file to get the book status, so save and flush
self.settings:saveSetting("summary", self.summary)
self.settings:flush()

@ -1,5 +1,6 @@
local BD = require("ui/bidi")
local Blitbuffer = require("ffi/blitbuffer")
local ButtonDialog = require("ui/widget/buttondialog")
local ButtonTable = require("ui/widget/buttontable")
local CenterContainer = require("ui/widget/container/centercontainer")
local CssTweaks = require("ui/data/css_tweaks")
@ -783,13 +784,123 @@ local BOOK_TWEAK_INPUT_HINT = T([[
%2]], _("You can add CSS snippets which will be applied only to this book."), BOOK_TWEAK_SAMPLE_CSS)
local CSS_SUGGESTIONS = {
{ "-cr-hint: footnote-inpage;", _("When set on a block element containing the target id of a href, this block element will be shown as an in-page footnote.")},
{ "-cr-hint: non-linear-combining;", _("Can be set on some specific DocFragments (ie. DocFragment[id*=16]) to ignore them in the linear pages flow.")},
{ "-cr-hint: toc-level1;", _("When set on an element, its text can be used to build the alternative table of contents.")},
{ "display: run-in !important;", _("When set on a block element, this element content will be inlined with the next block element.")},
{ "font-size: 1rem !important;", _("1rem will enforce your main font size.")},
{ "hyphens: none !important;", _("Disables hyphenation inside the targeted elements.")},
{ "text-indent: 1.2em !important;", _("1.2em is our default text indentation.")},
{ _("Long-press for info ⓘ"), _([[
This menu provides a non-exhaustive CSS syntax and properties list. It also shows some KOReader-specific, non-standard CSS features that can be useful with e-books.
Most of these bits are already used by our categorized 'Style tweaks' (found in the top menu). Long-press on any style-tweak option to see its code and its expected results. Should these not be enough to achieve your desired look, you may need to adjust them slightly: tap once on the CSS code-box to copy the code to the clipboard, paste it here and edit it.
Long-press on any item in this popup to get more information on what it does and what it can help solving.
Tap on the item to insert it: you can then edit it and combine it with others.]]), true },
{ _("Matching elements"), {
{ "p.className", _([[
p.className matches a <p> with class='className'.
*.className matches any element with class='className'.
p:not([class]) matches a <p> without any class= attribute.]])},
{ "aside > p", _([[
aside > p matches a <p> children of an <aside> element.
aside p (without any intermediate symbol) matches a <p> descendant of an <aside> element.]])},
{ "p + img", _([[
p + img matches a <img> if its immediate previous sibling is a <p>.
p ~ img matches a <img> if any of its previous siblings is a <p>.]])},
{ "p[name='what']", _([[
[name="what"] matches if the element has the attribute 'name' and its value is exactly 'what'.
[name] matches if the attribute 'name' is present.
[name~="what"] matches if the value of the attribute 'name' contains 'what' as a word (among other words separated by spaces).]])},
{ "p[name*='what' i]", _([[
[name*="what" i] matches any element having the attribute 'name' with a value that contains 'what', case insensitive.
[name^="what"] matches if the attribute value starts with 'what'.
[name$="what"] matches if the attribute value ends with 'what'.]])},
{ "p[_='what']", _([[
Similar in syntax to attribute matching, but matches the inner text of an element.
p[_="what"] matches any <p> whose text is exactly 'what'.
p[_] matches any non-empty <p>.
p:not([_]) matches any empty <p>.
p[_~="what"] matches any <p> that contains the word 'what'.]])},
{ "p[_*='what' i]", _([[
Similar in syntax to attribute matching, but matches the inner text of an element.
p[_*="what" i] matches any <p> that contains 'what', case insensitive.
p[_^="what"] matches any <p> whose text starts with 'what'.
(This can be used to match "Act" or "Scene", or character names in plays, and make them stand out.)
p[_$="what"] matches any <p> whose text ends with 'what'.]])},
{ "p:first-child", _([[
p:first-child matches a <p> that is the first child of its parent.
p:last-child matches a <p> that is the last child of its parent.
p:nth-child(odd) matches any other <p> in a series of sibling <p>.]])},
{ "Tip: use View HTML ⓘ", _([[
On a book page, select some text spanning around (before and after) the element you are interested in, and use 'View HTML'.
In the HTML viewer, long press on tags or text to get a list of selectors matching the element: tap on one of them to copy it to the clipboard.
You can then paste it here with long-press in the text box.]]), true},
}},
{ _("Common classic properties"), {
{ "font-size: 1rem !important;", _("1rem will enforce your main font size.")},
{ "font-weight: normal !important;", _("Remove bold. Use 'bold' to get bold.")},
{ "hyphens: none !important;", _("Disables hyphenation inside the targeted elements.")},
{ "text-indent: 1.2em !important;", _("1.2em is our default text indentation.")},
{ "break-before: always !important;", _("Start a new page with this element. Use 'avoid' to avoid a new page.")},
{ "color: black !important;", _("Force text to be black.")},
{ "background: transparent !important;", _("Remove any background color.")},
{ "max-width: 50vw !important;", _("Limit an element width to 50% of your screen width (use 'max-height: 50vh' for 50% of the screen height). Can be useful with <img> to limit their size.")},
}},
{ _("Private CSS properties"), {
{ "-cr-hint: footnote-inpage;", _("When set on a block element containing the target id of a href, this block element will be shown as an in-page footnote.")},
{ "-cr-hint: non-linear;", _("Can be set on some specific DocFragments (e.g. DocFragment[id$=_16]) to ignore them in the linear pages flow.")},
{ "-cr-hint: non-linear-combining;", _("Can be set on contiguous footnote blocks to ignore them in the linear pages flow.")},
{ "-cr-hint: toc-level1;", _("When set on an element, its text can be used to build the alternative table of contents. toc-level2 to toc-level6 can be used for nested chapters.")},
{ "-cr-hint: toc-ignore;", _("When set on an element, it will be ignored when building the alternative table of contents.")},
{ "-cr-hint: footnote;", _("Can be set on target of links (<div id='..'>) to have their link trigger as footnote popup, in case KOReader wrongly detect this target is not a footnote.")},
{ "-cr-hint: noteref;", _("Can be set on links (<a href='#..'>) to have them trigger as footnote popups, in case KOReader wrongly detect the links is not to a footnote.")},
{ "-cr-hint: noteref-ignore;", _([[
Can be set on links (<a href='#..'>) to have them NOT trigger footnote popups and in-page footnotes.
If some DocFragment presents an index of names with cross references, resulting in in-page footnotes taking half of these pages, you can avoid this with:
DocFragment[id$=_16] a { -cr-hint: noteref-ignore }]])},
}},
{ _("Useful 'content:' values"), {
{ _("Caution ⚠"), _([[
Be careful with these: stick them to a proper discriminating selector, like:
span.specificClassName
p[_*="keyword" i]
If used as-is, they will act on ALL elements!]]), true},
{ "::before {content: ' '}", _("Insert a visible space before an element.")},
{ "::before {content: '\\A0 '}", _("Insert a visible non-breakable space before an element, so it sticks to what's before.")},
{ "::before {content: '\\2060'}", _("U+2060 WORD JOINER may act as a glue (like an invisible non-breakable space) before an element, so it sticks to what's before.")},
{ "::before {content: '\\200B'}", _("U+200B ZERO WIDTH SPACE may allow a linebreak before an element, in case the absence of any space prevents that.")},
{ "::before {content: attr(title)}", _("Insert the value of the attribute 'title' at start of an element content.")},
{ "::before {content: '▶ '}", _("Prepend a visible marker.")},
{ "::before {content: '● '}", _("Prepend a visible marker.")},
{ "::before {content: '█ '}", _("Prepend a visible marker.")},
}},
}
function ReaderStyleTweak:editBookTweak(touchmenu_instance)
@ -869,19 +980,89 @@ function ReaderStyleTweak:editBookTweak(touchmenu_instance)
local suggestions_popup_widget
local buttons = {}
for _, suggestion in ipairs(CSS_SUGGESTIONS) do
local title = suggestion[1]
local is_submenu, submenu_items, description
if type(suggestion[2]) == "table" then
is_submenu = true
submenu_items = suggestion[2]
else
description = suggestion[2]
end
local is_info_only = suggestion[3]
local text
if is_submenu then -- add the same arrow we use for top menu submenus
text = require("ui/widget/menu").getMenuText({text=title, sub_item_table=true})
elseif is_info_only then
text = title
else
text = BD.ltr(title) -- CSS code, keep it LTR
end
table.insert(buttons, {{
text = suggestion[1],
text = text,
id = title,
align = "left",
callback = function()
UIManager:close(suggestions_popup_widget)
editor._input_widget:addChars(suggestion[1])
if is_info_only then
-- No CSS bit to insert, show description also on tap
UIManager:show(InfoMessage:new{ text = description })
return
end
if not is_submenu then -- insert as-is on tap
UIManager:close(suggestions_popup_widget)
editor:addTextToInput(title)
else
local sub_suggestions_popup_widget
local sub_buttons = {}
for _, sub_suggestion in ipairs(submenu_items) do
-- (No 2nd level submenu needed for now)
local sub_title = sub_suggestion[1]
local sub_description = sub_suggestion[2]
local sub_is_info_only = sub_suggestion[3]
local sub_text = sub_is_info_only and sub_title or BD.ltr(sub_title)
table.insert(sub_buttons, {{
text = sub_text,
align = "left",
callback = function()
if sub_is_info_only then
UIManager:show(InfoMessage:new{ text = sub_description })
return
end
UIManager:close(sub_suggestions_popup_widget)
UIManager:close(suggestions_popup_widget)
editor:addTextToInput(sub_title)
end,
hold_callback = sub_description and function()
UIManager:show(InfoMessage:new{ text = sub_description })
end,
}})
end
local anchor_func = function()
local d = suggestions_popup_widget:getButtonById(title).dimen:copy()
if BD.mirroredUILayout() then
d.x = d.x - d.w + Size.padding.default
else
d.x = d.x + d.w - Size.padding.default
end
-- As we don't know if we will pop up or down, anchor it on the middle of the item
d.y = d.y + math.floor(d.h / 2)
d.h = 1
return d, true
end
sub_suggestions_popup_widget = ButtonDialog:new{
modal = true, -- needed when keyboard is shown
width = math.floor(Screen:getWidth() * 0.9), -- max width, will get smaller
shrink_unneeded_width = true,
buttons = sub_buttons,
anchor = anchor_func,
}
UIManager:show(sub_suggestions_popup_widget)
end
end,
hold_callback = suggestion[2] and function()
UIManager:show(InfoMessage:new{ text = suggestion[2] })
hold_callback = description and function()
UIManager:show(InfoMessage:new{ text = description })
end or nil
}})
end
local ButtonDialog = require("ui/widget/buttondialog")
suggestions_popup_widget = ButtonDialog:new{
modal = true, -- needed when keyboard is shown
width = math.floor(Screen:getWidth() * 0.9), -- max width, will get smaller

@ -186,11 +186,11 @@ function ReaderThumbnail:removeFromCache(hash_subs, remove_only_non_matching)
return nb_removed, size_removed
end
function ReaderThumbnail:resetCachedPagesForBookmarks(...)
function ReaderThumbnail:resetCachedPagesForBookmarks(annotations)
-- Multiple bookmarks may be provided
local start_page, end_page
for i = 1, select("#", ...) do
local bm = select(i, ...)
for i = 1, #annotations do
local bm = annotations[i]
if self.ui.rolling then
-- Look at all properties that may be xpointers
for _, k in ipairs({"page", "pos0", "pos1"}) do
@ -537,9 +537,6 @@ end
ReaderThumbnail.onDocumentRerendered = ReaderThumbnail.resetCache
ReaderThumbnail.onDocumentPartiallyRerendered = ReaderThumbnail.resetCache
-- Emitted When adding/removing/updating bookmarks and highlights
ReaderThumbnail.onBookmarkAdded = ReaderThumbnail.resetCachedPagesForBookmarks
ReaderThumbnail.onBookmarkRemoved = ReaderThumbnail.resetCachedPagesForBookmarks
ReaderThumbnail.onBookmarkUpdated = ReaderThumbnail.resetCachedPagesForBookmarks
ReaderThumbnail.onBookmarkEdited = ReaderThumbnail.resetCachedPagesForBookmarks
ReaderThumbnail.onAnnotationsModified = ReaderThumbnail.resetCachedPagesForBookmarks
return ReaderThumbnail

@ -60,7 +60,9 @@ end
function ReaderToc:onGesture() end
function ReaderToc:registerKeyEvents()
if Device:hasKeyboard() then
if Device:hasScreenKB() then
self.key_events.ShowToc = { { "ScreenKB", "Up" } }
elseif Device:hasKeyboard() then
self.key_events.ShowToc = { { "T" } }
end
end
@ -104,6 +106,7 @@ end
function ReaderToc:resetToc()
self.toc = nil
self.toc_menu_items_built = false
self.toc_depth = nil
self.ticks = nil
self.ticks_flattened = nil
@ -314,6 +317,37 @@ function ReaderToc:validateAndFixToc()
self.toc_depth = max_depth
end
function ReaderToc:completeTocWithChapterLengths()
local toc = self.toc
local first = 1
local last = #toc
if last == 0 then
return
end
local prev_item_by_level = {}
for i = first, last do
local item = toc[i]
local page = item.page
local depth = item.depth
for j=#prev_item_by_level, depth, -1 do
local prev_item = prev_item_by_level[j]
if prev_item then
prev_item.chapter_length = page - prev_item.page
end
prev_item_by_level[j] = nil
end
prev_item_by_level[depth] = item
end
-- Set the length of the last ones
local page = self.ui.document:getPageCount()
for j=#prev_item_by_level, 0, -1 do
local prev_item = prev_item_by_level[j]
if prev_item then
prev_item.chapter_length = page - prev_item.page
end
end
end
function ReaderToc:getTocIndexByPage(pn_or_xp, skip_ignored_ticks)
self:fillToc()
if #self.toc == 0 then return end
@ -321,7 +355,7 @@ function ReaderToc:getTocIndexByPage(pn_or_xp, skip_ignored_ticks)
if type(pn_or_xp) == "string" then
return self:getAccurateTocIndexByXPointer(pn_or_xp, skip_ignored_ticks)
end
local prev_index = 1
local prev_index = 0
for _k,_v in ipairs(self.toc) do
if not skip_ignored_ticks or not self.toc_ticks_ignored_levels[_v.depth] then
if _v.page == pageno then
@ -336,7 +370,7 @@ function ReaderToc:getTocIndexByPage(pn_or_xp, skip_ignored_ticks)
prev_index = _k
end
end
return prev_index
return prev_index > 0 and prev_index or nil
end
function ReaderToc:getAccurateTocIndexByXPointer(xptr, skip_ignored_ticks)
@ -661,11 +695,16 @@ function ReaderToc:onShowToc()
local items_per_page = G_reader_settings:readSetting("toc_items_per_page") or self.toc_items_per_page_default
local items_font_size = G_reader_settings:readSetting("toc_items_font_size") or Menu.getItemFontSize(items_per_page)
local items_show_chapter_length = G_reader_settings:isTrue("toc_items_show_chapter_length")
local items_with_dots = G_reader_settings:nilOrTrue("toc_items_with_dots")
self:fillToc()
-- build menu items
if #self.toc > 0 and not self.toc[1].text then
if #self.toc > 0 and not self.toc_menu_items_built then
self.toc_menu_items_built = true
if items_show_chapter_length then
self:completeTocWithChapterLengths()
end
-- Have the width of 4 spaces be the unit of indentation
local tmp = TextWidget:new{
text = " ",
@ -679,6 +718,11 @@ function ReaderToc:onShowToc()
v.index = k
v.indent = toc_indent * (v.depth-1)
v.text = self:cleanUpTocTitle(v.title, true)
if items_show_chapter_length then
v.post_text = T("(%1)", v.chapter_length)
else
v.post_text = nil
end
v.bidi_wrap_func = BD.auto
v.mandatory = v.page
if has_hidden_flows then
@ -1147,6 +1191,17 @@ Enabling this option will restrict display to the chapter titles of progress bar
UIManager:show(items_font)
end,
}
menu_items.toc_items_show_chapter_length = {
text = _("Show chapter length"),
keep_menu_open = true,
checked_func = function()
return not G_reader_settings:nilOrFalse("toc_items_show_chapter_length")
end,
callback = function()
G_reader_settings:flipNilOrFalse("toc_items_show_chapter_length")
self.toc_menu_items_built = false
end
}
menu_items.toc_items_with_dots = {
text = _("With dots"),
keep_menu_open = true,

@ -17,7 +17,6 @@ local ReaderTypeset = WidgetContainer:extend{
-- @translators This is style in the sense meant by CSS (cascading style sheets), relating to the layout and presentation of the document. See <https://en.wikipedia.org/wiki/CSS> for more information.
css_menu_title = C_("CSS", "Style"),
css = nil,
internal_css = true,
unscaled_margins = nil,
}
@ -27,8 +26,16 @@ end
function ReaderTypeset:onReadSettings(config)
self.css = config:readSetting("css")
or G_reader_settings:readSetting("copt_css")
or self.ui.document.default_css
if not self.css then
if self.ui.document.is_fb2 then
self.css = G_reader_settings:readSetting("copt_fb2_css")
else
self.css = G_reader_settings:readSetting("copt_css")
end
end
if not self.css then
self.css = self.ui.document.default_css
end
local tweaks_css = self.ui.styletweak:getCssText()
self.ui.document:setStyleSheet(self.css, tweaks_css)
@ -93,7 +100,6 @@ function ReaderTypeset:onToggleEmbeddedStyleSheet(toggle)
else
self.configurable.embedded_css = 0
text = _("Disabled embedded styles.")
self:setStyleSheet(self.ui.document.default_css)
end
self.ui.document:setEmbeddedStyleSheet(self.configurable.embedded_css)
self.ui:handleEvent(Event:new("UpdatePos"))
@ -165,16 +171,17 @@ local OBSOLETED_CSS = {
}
function ReaderTypeset:genStyleSheetMenu()
local getStyleMenuItem = function(text, css_file, separator)
local getStyleMenuItem = function(text, css_file, description, fb2_compatible, separator)
return {
text_func = function()
return text .. (css_file == G_reader_settings:readSetting("copt_css") and "" or "")
local css_opt = self.ui.document.is_fb2 and "copt_fb2_css" or "copt_css"
return text .. (css_file == G_reader_settings:readSetting(css_opt) and "" or "")
end,
callback = function()
self:setStyleSheet(css_file or self.ui.document.default_css)
end,
hold_callback = function(touchmenu_instance)
self:makeDefaultStyleSheet(css_file, text, touchmenu_instance)
self:makeDefaultStyleSheet(css_file, text, description, touchmenu_instance)
end,
checked_func = function()
if not css_file then -- "Auto"
@ -182,6 +189,16 @@ function ReaderTypeset:genStyleSheetMenu()
end
return css_file == self.css
end,
enabled_func = function()
if fb2_compatible == true and not self.ui.document.is_fb2 then
return false
end
if fb2_compatible == false and self.ui.document.is_fb2 then
return false
end
-- if fb2_compatible==nil, we don't know (user css file)
return true
end,
separator = separator,
}
end
@ -189,8 +206,18 @@ function ReaderTypeset:genStyleSheetMenu()
local style_table = {}
local obsoleted_table = {}
table.insert(style_table, getStyleMenuItem(_("None"), ""))
table.insert(style_table, getStyleMenuItem(_("Auto"), nil, true))
table.insert(style_table, getStyleMenuItem(
_("None"),
"",
_("This sets an empty User-Agent stylesheet, and expects the document stylesheet to style everything (which publishers probably don't).\nThis is mostly only interesting for testing.")
))
table.insert(style_table, getStyleMenuItem(
_("Auto"),
nil,
_("This selects the default and preferred stylesheet for the document type."),
nil,
true -- separator
))
local css_files = {}
for f in lfs.dir("./data") do
@ -200,15 +227,39 @@ function ReaderTypeset:genStyleSheetMenu()
end
-- Add the 3 main styles
if css_files["epub.css"] then
table.insert(style_table, getStyleMenuItem(_("HTML / EPUB (epub.css)"), css_files["epub.css"]))
table.insert(style_table, getStyleMenuItem(
_("Traditional book look (epub.css)"),
css_files["epub.css"],
_([[
This is our book look-alike stylesheet: it extends the HTML standard stylesheet with styles aimed at making HTML content look more like a paper book (with justified text and indentation on paragraphs) than like a web page.
It is perfect for unstyled books, and might make styled books more readable.
It may cause some small issues on some books (miscentered titles, headings or separators, or unexpected text indentation), as publishers don't expect to have our added styles at play and need to reset them; try switching to html5.css when you notice such issues.]]),
false -- not fb2_compatible
))
css_files["epub.css"] = nil
end
if css_files["html5.css"] then
table.insert(style_table, getStyleMenuItem(_("HTML5 (html5.css)"), css_files["html5.css"]))
table.insert(style_table, getStyleMenuItem(
_("HTML Standard rendering (html5.css)"),
css_files["html5.css"],
_([[
This stylesheet conforms to the HTML Standard rendering suggestions (with a few limitations), similar to what most web browsers use.
As most publishers nowadays make and test their book with tools based on web browser engines, it is the stylesheet to use to see a book as these publishers intended.
On unstyled books though, it may give them the look of a web page (left aligned paragraphs without indentation and with spacing between them); try switching to epub.css when that happens.]]),
false -- not fb2_compatible
))
css_files["html5.css"] = nil
end
if css_files["fb2.css"] then
table.insert(style_table, getStyleMenuItem(_("FictionBook (fb2.css)"), css_files["fb2.css"], true))
table.insert(style_table, getStyleMenuItem(
_("FictionBook (fb2.css)"),
css_files["fb2.css"],
_([[
This stylesheet is to be used only with FB2 and FB3 documents, which are not classic HTML, and need some specific styling.
(FictionBook 2 & 3 are open XML-based e-book formats which originated and gained popularity in Russia.)]]),
true, -- fb2_compatible
true -- separator
))
css_files["fb2.css"] = nil
end
-- Add the obsoleted ones to the Obsolete sub menu
@ -216,7 +267,7 @@ function ReaderTypeset:genStyleSheetMenu()
for __, css in ipairs(OBSOLETED_CSS) do
obsoleted_css[css_files[css]] = css
if css_files[css] then
table.insert(obsoleted_table, getStyleMenuItem(css, css_files[css]))
table.insert(obsoleted_table, getStyleMenuItem(css, css_files[css], _("This stylesheet is obsolete: don't use it. It is kept solely to be able to open documents last read years ago and to migrate their highlights.")))
css_files[css] = nil
end
end
@ -227,7 +278,7 @@ function ReaderTypeset:genStyleSheetMenu()
end
table.sort(user_files)
for __, css in ipairs(user_files) do
table.insert(style_table, getStyleMenuItem(css, css_files[css]))
table.insert(style_table, getStyleMenuItem(css, css_files[css], _("This is a user added stylesheet.")))
end
style_table[#style_table].separator = true
@ -266,6 +317,7 @@ function ReaderTypeset:setStyleSheet(new_css)
end
end
-- Not used
function ReaderTypeset:setEmbededStyleSheetOnly()
if self.css ~= nil then
-- clear applied css
@ -355,11 +407,20 @@ function ReaderTypeset:addToMainMenu(menu_items)
}
end
function ReaderTypeset:makeDefaultStyleSheet(css, text, touchmenu_instance)
function ReaderTypeset:makeDefaultStyleSheet(css, name, description, touchmenu_instance)
local text = self.ui.document.is_fb2 and T(_("Set default style for FB2 documents to %1?"), BD.filename(name))
or T(_("Set default style to %1?"), BD.filename(name))
if description then
text = text .. "\n\n" .. description
end
UIManager:show(ConfirmBox:new{
text = T(_("Set default style to %1?"), BD.filename(text)),
text = text,
ok_callback = function()
G_reader_settings:saveSetting("copt_css", css)
if self.ui.document.is_fb2 then
G_reader_settings:saveSetting("copt_fb2_css", css)
else
G_reader_settings:saveSetting("copt_css", css)
end
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})

@ -84,9 +84,9 @@ local LANGUAGES = {
{ "pt-BR", {}, "HB ", _("Portuguese (BR)"), "Portuguese_BR.pattern" },
{ "rm", {"roh"}, "H ", _("Romansh"), "Romansh.pattern" },
{ "ro", {"ron"}, "H ", _("Romanian"), "Romanian.pattern" },
{ "ru", {"rus"}, "Hb ", _("Russian"), "Russian.pattern" },
{ "ru-GB", {}, "Hb ", _("Russian + English (UK)"), "Russian_EnGB.pattern" },
{ "ru-US", {}, "Hb ", _("Russian + English (US)"), "Russian_EnUS.pattern" },
{ "ru", {"rus"}, "HB ", _("Russian"), "Russian.pattern" },
{ "ru-GB", {}, "HB ", _("Russian + English (UK)"), "Russian_EnGB.pattern" },
{ "ru-US", {}, "HB ", _("Russian + English (US)"), "Russian_EnUS.pattern" },
{ "sr", {"srp"}, "HB ", _("Serbian"), "Serbian.pattern" },
{ "sk", {"slk"}, "HB ", _("Slovak"), "Slovak.pattern" },
{ "sl", {"slv"}, "H ", _("Slovenian"), "Slovenian.pattern" },

@ -95,7 +95,6 @@ function ReaderView:init()
temp_drawer = "invert",
temp = {},
saved_drawer = "lighten",
saved = {},
indicator = nil, -- geom: non-touch highlight position indicator: {x = 50, y=50}
}
self.page_states = {}
@ -210,22 +209,26 @@ function ReaderView:paintTo(bb, x, y)
end
end
-- dim last read area
-- mark last read area of overlapped pages
if not self.dim_area:isEmpty() and self:isOverlapAllowed() then
if self.page_overlap_style == "dim" then
bb:dimRect(
self.dim_area.x, self.dim_area.y,
self.dim_area.w, self.dim_area.h
)
elseif self.page_overlap_style == "arrow" then
local center_offset = bit.rshift(self.arrow.height, 1)
-- Paint at the proper y origin depending on wheter we paged forward (dim_area.y == 0) or backward
self.arrow:paintTo(bb, 0, self.dim_area.y == 0 and self.dim_area.h - center_offset or self.dim_area.y - center_offset)
elseif self.page_overlap_style == "line" then
bb:paintRect(0, self.dim_area.y == 0 and self.dim_area.h or self.dim_area.y,
self.dim_area.w, Size.line.medium, Blitbuffer.COLOR_BLACK)
bb:dimRect(self.dim_area.x, self.dim_area.y, self.dim_area.w, self.dim_area.h)
else
-- Paint at the proper y origin depending on whether we paged forward (dim_area.y == 0) or backward
local paint_y = self.dim_area.y == 0 and self.dim_area.h or self.dim_area.y
if self.page_overlap_style == "arrow" then
local center_offset = bit.rshift(self.arrow.height, 1)
self.arrow:paintTo(bb, 0, paint_y - center_offset)
elseif self.page_overlap_style == "line" then
bb:paintRect(0, paint_y, self.dim_area.w, Size.line.medium, Blitbuffer.COLOR_DARK_GRAY)
elseif self.page_overlap_style == "dashed_line" then
for i = 0, self.dim_area.w - 20, 20 do
bb:paintRect(i, paint_y, 14, Size.line.medium, Blitbuffer.COLOR_DARK_GRAY)
end
end
end
end
-- draw saved highlight
if self.highlight_visible then
self:drawSavedHighlight(bb, x, y)
@ -261,6 +264,10 @@ function ReaderView:paintTo(bb, x, y)
if self.ui.paging then
if self.document.hw_dithering then
self.dialog.dithered = true
-- Assume we're going to be showing colorful stuff on kaleido panels...
if Device:hasKaleidoWfm() then
UIManager:setDirty(nil, "color")
end
end
else
-- Whereas for CRe,
@ -276,6 +283,10 @@ function ReaderView:paintTo(bb, x, y)
if self.state.drawn == false and G_reader_settings:nilOrTrue("refresh_on_pages_with_images") then
UIManager:setDirty(nil, "full")
end
-- On Kaleido panels, we'll want to use GCC16 on the actual image, always...
if Device:hasKaleidoWfm() and img_coverage >= 0.075 then
UIManager:setDirty(nil, "color")
end
end
self.state.drawn = true
end
@ -522,6 +533,7 @@ function ReaderView:drawTempHighlight(bb, x, y)
end
function ReaderView:drawSavedHighlight(bb, x, y)
if #self.ui.annotation.annotations == 0 then return end
if self.ui.paging then
self:drawPageSavedHighlight(bb, x, y)
else
@ -529,45 +541,18 @@ function ReaderView:drawSavedHighlight(bb, x, y)
end
end
-- Returns the list of highlights in page.
-- The list includes full single-page highlights and parts of multi-page highlights.
function ReaderView:getPageSavedHighlights(page)
local highlights = {}
local is_reflow = self.document.configurable.text_wrap
self.document.configurable.text_wrap = 0
for page_num, page_highlights in pairs(self.highlight.saved) do
for i, highlight in ipairs(page_highlights) do
-- old single-page reflow highlights do not have page in position
local pos0_page = highlight.pos0.page or page_num
local pos1_page = highlight.pos1.page or page_num
if pos0_page <= page and page <= pos1_page then
if pos0_page == pos1_page then -- single-page highlight
table.insert(highlights, highlight)
else -- multi-page highlight
local item = self.ui.highlight:getSavedExtendedHighlightPage(highlight, page, i)
table.insert(highlights, item)
end
end
end
end
self.document.configurable.text_wrap = is_reflow
return highlights
end
function ReaderView:drawPageSavedHighlight(bb, x, y)
local pages = self:getCurrentPageList()
for _, page in ipairs(pages) do
local items = self:getPageSavedHighlights(page)
local items = self.ui.highlight:getPageSavedHighlights(page)
for _, item in ipairs(items) do
local boxes = self.document:getPageBoxesFromPositions(page, item.pos0, item.pos1)
if boxes then
local drawer = item.drawer or self.highlight.saved_drawer
local draw_note_mark = self.highlight.note_mark and
self.ui.bookmark:getBookmarkNote({datetime = item.datetime})
local draw_note_mark = item.note and self.highlight.note_mark
for _, box in ipairs(boxes) do
local rect = self:pageToScreenTransform(page, box)
if rect then
self:drawHighlightRect(bb, x, y, rect, drawer, draw_note_mark)
self:drawHighlightRect(bb, x, y, rect, item.drawer, draw_note_mark)
if draw_note_mark and self.highlight.note_mark == "sidemark" then
draw_note_mark = false -- side mark in the first line only
end
@ -583,48 +568,38 @@ function ReaderView:drawXPointerSavedHighlight(bb, x, y)
-- showing menu...). We might want to cache these boxes per page (and
-- clear that cache when page layout change or highlights are added
-- or removed).
local cur_view_top, cur_view_bottom
for _, items in pairs(self.highlight.saved) do
if items then
for j = 1, #items do
local item = items[j]
local pos0, pos1 = item.pos0, item.pos1
-- document:getScreenBoxesFromPositions() is expensive, so we
-- first check this item is on current page
if not cur_view_top then
-- Even in page mode, it's safer to use pos and ui.dimen.h
-- than pages' xpointers pos, even if ui.dimen.h is a bit
-- larger than pages' heights
cur_view_top = self.document:getCurrentPos()
if self.view_mode == "page" and self.document:getVisiblePageCount() > 1 then
cur_view_bottom = cur_view_top + 2 * self.ui.dimen.h
else
cur_view_bottom = cur_view_top + self.ui.dimen.h
end
end
local spos0 = self.document:getPosFromXPointer(pos0)
local spos1 = self.document:getPosFromXPointer(pos1)
local start_pos = math.min(spos0, spos1)
local end_pos = math.max(spos0, spos1)
if start_pos <= cur_view_bottom and end_pos >= cur_view_top then
local boxes = self.document:getScreenBoxesFromPositions(pos0, pos1, true) -- get_segments=true
if boxes then
local drawer = item.drawer or self.highlight.saved_drawer
local draw_note_mark = self.highlight.note_mark and
self.ui.bookmark:getBookmarkNote({datetime = item.datetime})
for _, box in ipairs(boxes) do
if box.h ~= 0 then
self:drawHighlightRect(bb, x, y, box, drawer, draw_note_mark)
if draw_note_mark and self.highlight.note_mark == "sidemark" then
draw_note_mark = false -- side mark in the first line only
end
-- Even in page mode, it's safer to use pos and ui.dimen.h
-- than pages' xpointers pos, even if ui.dimen.h is a bit
-- larger than pages' heights
local cur_view_top = self.document:getCurrentPos()
local cur_view_bottom
if self.view_mode == "page" and self.document:getVisiblePageCount() > 1 then
cur_view_bottom = cur_view_top + 2 * self.ui.dimen.h
else
cur_view_bottom = cur_view_top + self.ui.dimen.h
end
for _, item in ipairs(self.ui.annotation.annotations) do
if item.drawer then
-- document:getScreenBoxesFromPositions() is expensive, so we
-- first check if this item is on current page
local start_pos = self.document:getPosFromXPointer(item.pos0)
local end_pos = self.document:getPosFromXPointer(item.pos1)
if start_pos <= cur_view_bottom and end_pos >= cur_view_top then
local boxes = self.document:getScreenBoxesFromPositions(item.pos0, item.pos1, true) -- get_segments=true
if boxes then
local draw_note_mark = item.note and self.highlight.note_mark
for _, box in ipairs(boxes) do
if box.h ~= 0 then
self:drawHighlightRect(bb, x, y, box, item.drawer, draw_note_mark)
if draw_note_mark and self.highlight.note_mark == "sidemark" then
draw_note_mark = false -- side mark in the first line only
end
end -- end for each box
end -- end if boxes
end
end
end
end -- end for each highlight
end
end
end -- end for all saved highlight
end
end
function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, draw_note_mark)
@ -632,7 +607,7 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, draw_note_mark)
if drawer == "lighten" then
bb:lightenRect(x, y, w, h, self.highlight.lighten_factor)
elseif drawer == "underscore" then
bb:paintRect(x, y + h - 1, w, Size.line.medium, Blitbuffer.COLOR_GRAY)
bb:paintRect(x, y + h - 1, w, Size.line.thick, Blitbuffer.COLOR_GRAY_4)
elseif drawer == "strikeout" then
local line_y = y + math.floor(h / 2) + 1
if self.ui.paging then
@ -695,7 +670,8 @@ function ReaderView:recalculate()
-- start from right of page_area
self.visible_area.x = self.page_area.x + self.page_area.w - self.visible_area.w
end
if self.document.configurable.zoom_direction >= 2 and self.document.configurable.zoom_direction <= 5 then -- zoom_bottom_to_top
-- Check if we are in zoom_bottom_to_top
if self.document.configurable.zoom_direction and self.document.configurable.zoom_direction >= 2 and self.document.configurable.zoom_direction <= 5 then
-- starts from bottom of page_area
self.visible_area.y = self.page_area.y + self.page_area.h - self.visible_area.h
else
@ -817,7 +793,7 @@ function ReaderView:onSetRotationMode(rotation)
if rotation ~= nil then
local old_rotation = Screen:getRotationMode()
if rotation == old_rotation then
return true
return
end
-- NOTE: We cannot rely on getScreenMode, as it actually checks the screen dimensions, instead of the rotation mode.
@ -834,7 +810,7 @@ function ReaderView:onSetRotationMode(rotation)
Screen:setRotationMode(rotation)
UIManager:setDirty(self.dialog, "full")
Notification:notify(T(_("Rotation mode set to: %1"), optionsutil:getOptionText("SetRotationMode", rotation)))
return true
return
end
Screen:setRotationMode(rotation)
@ -846,7 +822,7 @@ function ReaderView:onSetRotationMode(rotation)
self.ui:onScreenResize(new_screen_size)
self.ui:handleEvent(Event:new("InitScrollPageStates"))
Notification:notify(T(_("Rotation mode set to: %1"), optionsutil:getOptionText("SetRotationMode", rotation)))
return true
return
end
function ReaderView:onSetDimensions(dimensions)
@ -913,40 +889,6 @@ function ReaderView:onReadSettings(config)
self:resetLayout()
local page_scroll = config:readSetting("kopt_page_scroll") or self.document.configurable.page_scroll
self.page_scroll = page_scroll == 1 and true or false
self.highlight.saved = config:readSetting("highlight", {})
-- Highlight formats in crengine and mupdf are incompatible.
-- Backup highlights when the document is opened with incompatible engine.
local page, page_highlights
while true do -- remove empty tables for pages without highlights and get the first page with highlights
page, page_highlights = next(self.highlight.saved)
if not page or #page_highlights > 0 then
break -- we're done (there is none, or there is some usable)
else
self.highlight.saved[page] = nil -- clean it up while we're at it, and find another one
end
end
if page_highlights then
local highlight_type = type(page_highlights[1].pos0)
if self.ui.rolling and highlight_type == "table" then
config:saveSetting("highlight_paging", self.highlight.saved)
self.highlight.saved = config:readSetting("highlight_rolling", {})
config:saveSetting("highlight", self.highlight.saved)
config:delSetting("highlight_rolling")
elseif self.ui.paging and highlight_type == "string" then
config:saveSetting("highlight_rolling", self.highlight.saved)
self.highlight.saved = config:readSetting("highlight_paging", {})
config:saveSetting("highlight", self.highlight.saved)
config:delSetting("highlight_paging")
end
else
if self.ui.rolling and config:has("highlight_rolling") then
self.highlight.saved = config:readSetting("highlight_rolling")
config:delSetting("highlight_rolling")
elseif self.ui.paging and config:has("highlight_paging") then
self.highlight.saved = config:readSetting("highlight_paging")
config:delSetting("highlight_paging")
end
end
self.inverse_reading_order = config:isTrue("inverse_reading_order") or G_reader_settings:isTrue("inverse_reading_order")
self.page_overlap_enable = config:isTrue("show_overlap_enable") or G_reader_settings:isTrue("page_overlap_enable") or G_defaults:readSetting("DSHOWOVERLAP")
self.page_overlap_style = config:readSetting("page_overlap_style") or G_reader_settings:readSetting("page_overlap_style") or "dim"
@ -1106,7 +1048,6 @@ function ReaderView:onSaveSettings()
if G_reader_settings:nilOrFalse("lock_rotation") then
self.document.configurable.rotation_mode = Screen:getRotationMode() -- will be saved by ReaderConfig
end
self.ui.doc_settings:saveSetting("highlight", self.highlight.saved)
self.ui.doc_settings:saveSetting("inverse_reading_order", self.inverse_reading_order)
self.ui.doc_settings:saveSetting("show_overlap_enable", self.page_overlap_enable)
self.ui.doc_settings:saveSetting("page_overlap_style", self.page_overlap_style)

@ -113,6 +113,17 @@ function ReaderWikipedia:addToMainMenu(menu_items)
})
end,
}
local function genChoiceMenuEntry(title, setting, value, default)
return {
text = title,
checked_func = function()
return G_reader_settings:readSetting(setting, default) == value
end,
callback = function()
G_reader_settings:saveSetting(setting, value)
end,
}
end
menu_items.wikipedia_settings = {
text = _("Wikipedia settings"),
sub_item_table = {
@ -170,6 +181,7 @@ function ReaderWikipedia:addToMainMenu(menu_items)
UIManager:show(wikilang_input)
wikilang_input:onShowKeyboard()
end,
separator = true,
},
{ -- setting used by dictquicklookup
text = _("Set Wikipedia 'Save as EPUB' folder"),
@ -199,6 +211,41 @@ You can choose an existing folder, or use a default folder named "Wikipedia" in
callback = function()
G_reader_settings:flipNilOrFalse("wikipedia_save_in_book_dir")
end,
},
{ -- setting used in wikipedia.lua
text_func = function()
local include_images = _("ask")
if G_reader_settings:readSetting("wikipedia_epub_include_images") == true then
include_images = _("always")
elseif G_reader_settings:readSetting("wikipedia_epub_include_images") == false then
include_images = _("never")
end
return T(_("Include images in EPUB: %1"), include_images)
end,
sub_item_table = {
genChoiceMenuEntry(_("Ask"), "wikipedia_epub_include_images", nil),
genChoiceMenuEntry(_("Include images"), "wikipedia_epub_include_images", true),
genChoiceMenuEntry(_("Don't include images"), "wikipedia_epub_include_images", false),
},
},
{ -- setting used in wikipedia.lua
text_func = function()
local images_quality = _("ask")
if G_reader_settings:readSetting("wikipedia_epub_highres_images") == true then
images_quality = _("higher")
elseif G_reader_settings:readSetting("wikipedia_epub_highres_images") == false then
images_quality = _("standard")
end
return T(_("Images quality in EPUB: %1"), images_quality)
end,
enabled_func = function()
return G_reader_settings:readSetting("wikipedia_epub_include_images") ~= false
end,
sub_item_table = {
genChoiceMenuEntry(_("Ask"), "wikipedia_epub_highres_images", nil),
genChoiceMenuEntry(_("Standard quality"), "wikipedia_epub_highres_images", false),
genChoiceMenuEntry(_("Higher quality"), "wikipedia_epub_highres_images", true),
},
separator = true,
},
{

@ -230,11 +230,10 @@ function ReaderZooming:onReadSettings(config)
-- Otherwise, build it from the split genus & type settings
local zoom_mode_genus = config:readSetting("kopt_zoom_mode_genus")
or G_reader_settings:readSetting("kopt_zoom_mode_genus")
or 3 -- autocrop is default then pagewidth will be the default as well
local zoom_mode_type = config:readSetting("kopt_zoom_mode_type")
or G_reader_settings:readSetting("kopt_zoom_mode_type")
if zoom_mode_genus or zoom_mode_type then
zoom_mode = self:combo_to_mode(zoom_mode_genus, zoom_mode_type)
end
zoom_mode = self:combo_to_mode(zoom_mode_genus, zoom_mode_type)
-- Validate it
zoom_mode = self.zoom_mode_label[zoom_mode] and zoom_mode or self.DEFAULT_ZOOM_MODE

@ -21,9 +21,11 @@ local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog")
local LanguageSupport = require("languagesupport")
local NetworkListener = require("ui/network/networklistener")
local Notification = require("ui/widget/notification")
local PluginLoader = require("pluginloader")
local ReaderActivityIndicator = require("apps/reader/modules/readeractivityindicator")
local ReaderAnnotation = require("apps/reader/modules/readerannotation")
local ReaderBack = require("apps/reader/modules/readerback")
local ReaderBookmark = require("apps/reader/modules/readerbookmark")
local ReaderConfig = require("apps/reader/modules/readerconfig")
@ -60,6 +62,7 @@ local Screenshoter = require("ui/widget/screenshoter")
local SettingsMigration = require("ui/data/settings_migration")
local UIManager = require("ui/uimanager")
local ffiUtil = require("ffi/util")
local filemanagerutil = require("apps/filemanager/filemanagerutil")
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local time = require("ui/time")
@ -83,7 +86,7 @@ local ReaderUI = InputContainer:extend{
password = nil,
postInitCallback = nil,
postReaderCallback = nil,
postReaderReadyCallback = nil,
}
function ReaderUI:registerModule(name, ui_module, always_active)
@ -102,8 +105,8 @@ function ReaderUI:registerPostInitCallback(callback)
table.insert(self.postInitCallback, callback)
end
function ReaderUI:registerPostReadyCallback(callback)
table.insert(self.postReaderCallback, callback)
function ReaderUI:registerPostReaderReadyCallback(callback)
table.insert(self.postReaderReadyCallback, callback)
end
function ReaderUI:init()
@ -116,7 +119,7 @@ function ReaderUI:init()
Device:setIgnoreInput(true) -- Avoid ANRs on Android with unprocessed events.
self.postInitCallback = {}
self.postReaderCallback = {}
self.postReaderReadyCallback = {}
-- if we are not the top level dialog ourselves, it must be given in the table
if not self.dialog then
self.dialog = self
@ -182,6 +185,12 @@ function ReaderUI:init()
view = self.view,
ui = self
})
self:registerModule("annotation", ReaderAnnotation:new{
dialog = self.dialog,
view = self.view,
ui = self,
document = self.document,
})
-- reader goto controller
-- "goto" being a dirty keyword in Lua?
self:registerModule("gotopage", ReaderGoto:new{
@ -427,6 +436,12 @@ function ReaderUI:init()
view = self.view,
ui = self,
})
self:registerModule("networklistener", NetworkListener:new {
document = self.document,
view = self.view,
ui = self,
})
-- koreader plugins
for _, plugin_module in ipairs(PluginLoader:loadPlugins()) do
local ok, plugin_or_err = PluginLoader:createPluginInstance(
@ -444,15 +459,6 @@ function ReaderUI:init()
end
end
if Device:hasWifiToggle() then
local NetworkListener = require("ui/network/networklistener")
self:registerModule("networklistener", NetworkListener:new {
document = self.document,
view = self.view,
ui = self,
})
end
-- Allow others to change settings based on external factors
-- Must be called after plugins are loaded & before setting are read.
self:handleEvent(Event:new("DocSettingsLoad", self.doc_settings, self.document))
@ -491,10 +497,10 @@ function ReaderUI:init()
-- Need the same event for PDF document
self:handleEvent(Event:new("ReaderReady", self.doc_settings))
for _,v in ipairs(self.postReaderCallback) do
for _,v in ipairs(self.postReaderReadyCallback) do
v()
end
self.postReaderCallback = nil
self.postReaderReadyCallback = nil
Device:setIgnoreInput(false) -- Allow processing of events (on Android).
Input:inhibitInputUntil(0.2)
@ -517,6 +523,18 @@ function ReaderUI:registerKeyEvents()
if Device:hasKeys() then
self.key_events.Home = { { "Home" } }
self.key_events.Reload = { { "F5" } }
if Device:hasDPad() and Device:useDPadAsActionKeys() then
self.key_events.KeyContentSelection = { { { "Up", "Down" } }, event = "StartHighlightIndicator" }
end
if Device:hasScreenKB() or Device:hasSymKey() then
if Device:hasKeyboard() then
self.key_events.KeyToggleWifi = { { "Shift", "Home" }, event = "ToggleWifi" }
self.key_events.OpenLastDoc = { { "Shift", "Back" } }
else -- Currently exclusively targets Kindle 4.
self.key_events.KeyToggleWifi = { { "ScreenKB", "Home" }, event = "ToggleWifi" }
self.key_events.OpenLastDoc = { { "ScreenKB", "Back" } }
end
end
end
end
@ -551,7 +569,6 @@ function ReaderUI:showFileManager(file)
local last_dir, last_file
if file then
last_dir = util.splitFilePathName(file)
last_dir = last_dir:match("(.*)/")
last_file = file
else
last_dir, last_file = self:getLastDirFile(true)
@ -584,16 +601,17 @@ end
function ReaderUI:showReader(file, provider, seamless)
logger.dbg("show reader ui")
file = ffiUtil.realpath(file)
if lfs.attributes(file, "mode") ~= "file" then
UIManager:show(InfoMessage:new{
text = T(_("File '%1' does not exist."), BD.filepath(file))
text = T(_("File '%1' does not exist."), BD.filepath(filemanagerutil.abbreviate(file)))
})
return
end
if not DocumentRegistry:hasProvider(file) and provider == nil then
UIManager:show(InfoMessage:new{
text = T(_("File '%1' is not supported."), BD.filepath(file))
text = T(_("File '%1' is not supported."), BD.filepath(filemanagerutil.abbreviate(file)))
})
self:showFileManager(file)
return
@ -609,7 +627,7 @@ end
function ReaderUI:showReaderCoroutine(file, provider, seamless)
UIManager:show(InfoMessage:new{
text = T(_("Opening file '%1'."), BD.filepath(file)),
text = T(_("Opening file '%1'."), BD.filepath(filemanagerutil.abbreviate(file))),
timeout = 0.0,
invisible = seamless,
})

@ -204,6 +204,19 @@ if Device:hasGSensor() then
Notification:notify(new_text)
return true
end
function DeviceListener:onLockGSensor()
G_reader_settings:flipNilOrFalse("input_lock_gsensor")
Device:lockGSensor(G_reader_settings:isTrue("input_lock_gsensor"))
local new_text
if G_reader_settings:isTrue("input_lock_gsensor") then
new_text = _("Orientation locked.")
else
new_text = _("Orientation unlocked.")
end
Notification:notify(new_text)
return true
end
end
if not Device:isAlwaysFullscreen() then

@ -41,8 +41,11 @@ local Device = {
hasAuxBattery = no,
hasKeyboard = no,
hasKeys = no,
hasScreenKB = no, -- in practice only some Kindles
hasSymKey = no, -- in practice only some Kindles
canKeyRepeat = no,
hasDPad = no,
useDPadAsActionKeys = no,
hasExitOptions = yes,
hasFewKeys = no,
hasWifiToggle = yes,
@ -62,6 +65,7 @@ local Device = {
hasExternalSD = no, -- or other storage volume that cannot be accessed using the File Manager
canHWDither = no,
canHWInvert = no,
hasKaleidoWfm = no,
canDoSwipeAnimation = no,
canModifyFBInfo = no, -- some NTX boards do wonky things with the rotate flag after a FBIOPUT_VSCREENINFO ioctl
canUseCBB = yes, -- The C BB maintains a 1:1 feature parity with the Lua BB, except that is has NO support for BB4, and limited support for BBRGB24
@ -568,7 +572,7 @@ function Device:exit()
G_reader_settings:close()
-- I/O teardown
require("ffi/input"):closeAll()
self.input.teardown()
end
-- Lifted from busybox's libbb/inet_cksum.c

@ -1141,7 +1141,7 @@ function Contact:handleTwoFingerPan(buddy_contact)
ges_ev._end_pos = nil
end
ges_ev.direction = gesture_detector.DIRECTION_TABLE[tpan_dir]
-- Use the the sum of both contacts' travel for the distance
-- Use the sum of both contacts' travel for the distance
ges_ev.distance = tpan_dis + rpan_dis
-- Some handlers might also want to know the distance between the two contacts on lift & down.
ges_ev.span = end_distance

@ -139,7 +139,7 @@ local Input = {
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"Up", "Down", "Left", "Right", "Press", "Backspace", "End",
"Back", "Sym", "AA", "Menu", "Home", "Del",
"Back", "Sym", "AA", "Menu", "Home", "Del", "ScreenKB",
"LPgBack", "RPgBack", "LPgFwd", "RPgFwd"
},
},
@ -171,6 +171,7 @@ local Input = {
Shift = false,
Sym = false,
Meta = false,
ScreenKB = false,
},
-- repeat state:
@ -178,6 +179,7 @@ local Input = {
-- touch state:
main_finger_slot = 0,
pen_slot = 4,
cur_slot = 0,
MTSlots = nil, -- table, object may be replaced at runtime
active_slots = nil, -- ditto
@ -194,6 +196,10 @@ local Input = {
setClipboardText = function(text)
_internal_clipboard_text = text or ""
end,
-- open'ed input devices hashmap (key: path, value: fd number)
-- Must be a class member, both because Input is a singleton and that state is process-wide anyway.
opened_devices = {},
}
function Input:new(o)
@ -219,6 +225,10 @@ function Input:init()
},
}
-- Always send pen data to a slot far enough away from our main finger slot that it can never be matched with a finger buddy in GestureDetector (i.e., +/- 1),
-- with an extra bit of leeway, since we don't even actually support three finger gestures ;).
self.pen_slot = self.main_finger_slot + 4
self.gesture_detector = GestureDetector:new{
screen = self.device.screen,
input = self,
@ -290,14 +300,97 @@ function Input:disableRotationMap()
end
--[[--
Wrapper for FFI input open.
Wrapper for our Lua/C input module's open.
Note that we adhere to the "." syntax here for compatibility.
@todo Clean up separation FFI/this.
The `name` argument is optional, and used for logging purposes only.
--]]
function Input.open(device, is_emu_events)
return input.open(device, is_emu_events and 1 or 0)
function Input.open(path, name)
-- Make sure we don't open the same device twice.
if not Input.opened_devices[path] then
local fd = input.open(path)
if fd then
Input.opened_devices[path] = fd
if name then
logger.dbg("Opened fd", fd, "for input device", name, "@", path)
else
logger.dbg("Opened fd", fd, "for input device @", path)
end
end
-- No need to log failures, input will have raised an error already,
-- and we want to make those fatal, so we don't protect this call.
return fd
end
end
--[[--
Wrapper for our Lua/C input module's fdopen.
Note that we adhere to the "." syntax here for compatibility.
The `name` argument is optional, and used for logging purposes only.
`path` is mandatory, though!
--]]
function Input.fdopen(fd, path, name)
-- Make sure we don't open the same device twice.
if not Input.opened_devices[path] then
input.fdopen(fd)
-- As with input.open, it will throw on error (closing the fd first)
Input.opened_devices[path] = fd
if name then
logger.dbg("Kept fd", fd, "open for input device", name, "@", path)
else
logger.dbg("Kept fd", fd, "open for input device @", path)
end
return fd
end
end
--[[--
Wrapper for our Lua/C input module's close.
Note that we adhere to the "." syntax here for compatibility.
--]]
function Input.close(path)
-- Make sure we actually know about this device
local fd = Input.opened_devices[path]
if fd then
local ok, err = input.close(fd)
if ok or err == C.ENODEV then
-- Either the call succeeded,
-- or the backend had already caught an ENODEV in waitForInput and closed the fd internally.
-- (Because the EvdevInputRemove Event comes from an UsbDevicePlugOut uevent forwarded as an... *input* EV_KEY event ;)).
-- Regardless, that device is gone, so clear its spot in the hashmap.
Input.opened_devices[path] = nil
end
else
logger.warn("Tried to close an unknown input device @", path)
end
end
--[[--
Wrapper for our Lua/C input module's closeAll.
Note that we adhere to the "." syntax here for compatibility.
--]]
function Input.teardown()
input.closeAll()
Input.opened_devices = {}
end
-- Wrappers for the custom FFI implementations with no concept of paths or fd
if input.is_ffi then
-- Pass args as-is. None of 'em actually *take* arguments, but some may be invoked as methods...
function Input.open(...)
return input.open(...)
end
function Input.close(...)
return input.close(...)
end
function Input.teardown(...)
return input.closeAll(...)
end
end
--[[--
@ -563,24 +656,30 @@ function Input:handleKeyBoardEv(ev)
end
elseif self.wacom_protocol then
if ev.code == C.BTN_TOOL_PEN then
-- Always send pen data to slot 2
self:setupSlotData(2)
-- Switch to the dedicated pen slot, and make sure it's active, as this can come in a dedicated input frame
self:setupSlotData(self.pen_slot)
if ev.value == 1 then
self:setCurrentMtSlot("tool", TOOL_TYPE_PEN)
else
self:setCurrentMtSlot("tool", TOOL_TYPE_FINGER)
-- Switch back to our main finger slot
self.cur_slot = self.main_finger_slot
end
return
elseif ev.code == C.BTN_TOUCH then
-- BTN_TOUCH is bracketed by BTN_TOOL_PEN, so we can limit this to pens, to avoid stomping on panel slots.
if self:getCurrentMtSlotData("tool") == TOOL_TYPE_PEN then
-- Make sure the pen slot is active, as this can come in a dedicated input frame
-- (i.e., we need it to be referenced by self.MTSlots for the lift to be picked up in the EV_SYN:SYN_REPORT handler).
-- (Conversely, getCurrentMtSlotData pokes at the *persistent* slot data in self.ev_slots,
-- so it can keep track of data across input frames).
self:setupSlotData(self.pen_slot)
-- Much like on snow, use this to detect contact down & lift,
-- as ABS_PRESSURE may be entirely omitted from hover events,
-- and ABS_DISTANCE is not very clear cut...
self:setupSlotData(2)
if ev.value == 1 then
self:setCurrentMtSlot("id", 2)
self:setCurrentMtSlot("id", self.pen_slot)
else
self:setCurrentMtSlot("id", -1)
end
@ -721,6 +820,16 @@ function Input:handlePowerManagementOnlyEv(ev)
end
end
-- Make sure we don't leave modifiers in an inconsistent state
if self.modifiers[keycode] ~= nil then
if ev.value == KEY_PRESS then
self.modifiers[keycode] = true
elseif ev.value == KEY_RELEASE then
self.modifiers[keycode] = false
end
return
end
-- Nothing to see, move along!
return
end

@ -3,7 +3,6 @@ local UIManager
local time = require("ui/time")
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local util = require("util")
-- We're going to need a few <linux/fb.h> & <linux/input.h> constants...
local ffi = require("ffi")
@ -11,6 +10,7 @@ local C = ffi.C
require("ffi/linux_fb_h")
require("ffi/linux_input_h")
require("ffi/posix_h")
require("ffi/fbink_input_h")
local function yes() return true end
local function no() return false end -- luacheck: ignore
@ -206,6 +206,58 @@ function Kindle:supportsScreensaver()
end
end
function Kindle:openInputDevices()
-- Auto-detect input devices (via FBInk's fbink_input_scan)
local ok, FBInkInput = pcall(ffi.load, "fbink_input")
if not ok then
-- NOP fallback for the testsuite...
FBInkInput = { fbink_input_scan = function() end }
end
local dev_count = ffi.new("size_t[1]")
-- We care about: the touchscreen, a properly scaled stylus, pagination buttons, a home button and a fiveway.
local match_mask = bit.bor(C.INPUT_TOUCHSCREEN, C.INPUT_SCALED_TABLET, C.INPUT_PAGINATION_BUTTONS, C.INPUT_HOME_BUTTON, C.INPUT_DPAD)
local devices = FBInkInput.fbink_input_scan(match_mask, 0, 0, dev_count)
if devices ~= nil then
for i = 0, tonumber(dev_count[0]) - 1 do
local dev = devices[i]
if dev.matched then
self.input.fdopen(tonumber(dev.fd), ffi.string(dev.path), ffi.string(dev.name))
end
end
C.free(devices)
else
-- Auto-detection failed, warn and fall back to defaults
logger.warn("We failed to auto-detect the proper input devices, input handling may be inconsistent!")
if self.touch_dev then
-- We've got a preferred path specified for the touch panel
self.input.open(self.touch_dev)
else
-- That generally works out well enough on legacy devices...
self.input.open("/dev/input/event0")
self.input.open("/dev/input/event1")
end
end
-- Getting the device where rotation events end up without catching a bunch of false-positives is... trickier,
-- thanks to the inane event code being used...
if self:hasGSensor() then
-- i.e., we want something that reports EV_ABS:ABS_PRESSURE that isn't *also* a pen (because those are pretty much guaranteed to report pressure...).
-- And let's add that isn't also a touchscreen to the mix, because while not true at time of writing, that's an event touchscreens sure can support...
devices = FBInkInput.fbink_input_scan(C.INPUT_ROTATION_EVENT, bit.bor(C.INPUT_TABLET, C.INPUT_TOUCHSCREEN), C.NO_RECAP, dev_count)
if devices ~= nil then
for i = 0, tonumber(dev_count[0]) - 1 do
local dev = devices[i]
if dev.matched then
self.input.fdopen(tonumber(dev.fd), ffi.string(dev.path), ffi.string(dev.name))
end
end
C.free(devices)
end
end
self.input.open("fake_events")
end
function Kindle:init()
-- Check if the device supports deep sleep/quick boot
if lfs.attributes("/sys/devices/platform/falconblk/uevent", "mode") == "file" then
@ -234,6 +286,14 @@ function Kindle:init()
self.canDeepSleep = false
end
-- If the device-specific init hasn't done so already (devices without keys don't), instantiate Input.
if not self.input then
self.input = require("device/input"):new{ device = self }
end
-- Auto-detect & open input devices
self:openInputDevices()
Generic.init(self)
end
@ -458,7 +518,9 @@ local Kindle2 = Kindle:extend{
isREAGL = no,
hasKeyboard = yes,
hasKeys = yes,
hasSymKey = yes,
hasDPad = yes,
useDPadAsActionKeys = yes,
canHWInvert = no,
canModifyFBInfo = no,
canUseCBB = no, -- 4bpp
@ -471,7 +533,9 @@ local KindleDXG = Kindle:extend{
isREAGL = no,
hasKeyboard = yes,
hasKeys = yes,
hasSymKey = yes,
hasDPad = yes,
useDPadAsActionKeys = yes,
canHWInvert = no,
canModifyFBInfo = no,
canUseCBB = no, -- 4bpp
@ -484,7 +548,9 @@ local Kindle3 = Kindle:extend{
isREAGL = no,
hasKeyboard = yes,
hasKeys = yes,
hasSymKey = yes,
hasDPad = yes,
useDPadAsActionKeys = yes,
canHWInvert = no,
canModifyFBInfo = no,
canUseCBB = no, -- 4bpp
@ -495,7 +561,9 @@ local Kindle4 = Kindle:extend{
model = "Kindle4",
isREAGL = no,
hasKeys = yes,
hasScreenKB = yes,
hasDPad = yes,
useDPadAsActionKeys = yes,
canHWInvert = no,
canModifyFBInfo = no,
-- NOTE: It could *technically* use the C BB, as it's running @ 8bpp, but it's expecting an inverted palette...
@ -683,9 +751,6 @@ function Kindle2:init()
device = self,
event_map = require("device/kindle/event_map_keyboard"),
}
self.input.open("/dev/input/event0")
self.input.open("/dev/input/event1")
self.input.open("fake_events")
Kindle.init(self)
end
@ -700,9 +765,6 @@ function KindleDXG:init()
event_map = require("device/kindle/event_map_keyboard"),
}
self.keyboard_layout = require("device/kindle/keyboard_layout")
self.input.open("/dev/input/event0")
self.input.open("/dev/input/event1")
self.input.open("fake_events")
Kindle.init(self)
end
@ -718,9 +780,6 @@ function Kindle3:init()
event_map = require("device/kindle/event_map_kindle4"),
}
self.keyboard_layout = require("device/kindle/keyboard_layout")
self.input.open("/dev/input/event0")
self.input.open("/dev/input/event1")
self.input.open("fake_events")
Kindle.init(self)
end
@ -735,9 +794,6 @@ function Kindle4:init()
device = self,
event_map = require("device/kindle/event_map_kindle4"),
}
self.input.open("/dev/input/event0")
self.input.open("/dev/input/event1")
self.input.open("fake_events")
Kindle.init(self)
end
@ -757,11 +813,6 @@ function KindleTouch:init()
-- Kindle Touch needs event modification for proper coordinates
self.input:registerEventAdjustHook(self.input.adjustTouchScale, {x=600/4095, y=800/4095})
-- event0 in KindleTouch is "WM8962 Beep Generator" (useless)
-- event1 in KindleTouch is "imx-yoshi Headset" (useless)
self.input.open("/dev/input/event2") -- Home button
self.input.open(self.touch_dev) -- touchscreen
self.input.open("fake_events")
Kindle.init(self)
end
@ -775,9 +826,6 @@ function KindlePaperWhite:init()
}
Kindle.init(self)
self.input.open(self.touch_dev)
self.input.open("fake_events")
end
function KindlePaperWhite2:init()
@ -791,9 +839,6 @@ function KindlePaperWhite2:init()
}
Kindle.init(self)
self.input.open(self.touch_dev)
self.input.open("fake_events")
end
function KindleBasic:init()
@ -806,9 +851,6 @@ function KindleBasic:init()
}
Kindle.init(self)
self.input.open(self.touch_dev)
self.input.open("fake_events")
end
function KindleVoyage:init()
@ -859,11 +901,7 @@ function KindleVoyage:init()
Kindle.init(self)
self.input.open(self.touch_dev)
self.input.open("/dev/input/event2") -- WhisperTouch
self.input.open("fake_events")
-- reenable WhisperTouch keys when started without framework
-- Re-enable WhisperTouch keys when started without framework
if self.framework_lipc_handle then
self.framework_lipc_handle:set_int_property("com.lab126.deviced", "fsrkeypadEnable", 1)
self.framework_lipc_handle:set_int_property("com.lab126.deviced", "fsrkeypadPrevEnable", 1)
@ -882,9 +920,6 @@ function KindlePaperWhite3:init()
}
Kindle.init(self)
self.input.open(self.touch_dev)
self.input.open("fake_events")
end
-- HAL for gyro orientation switches (EV_ABS:ABS_PRESSURE (?!) w/ custom values to EV_MSC:MSC_GYRO w/ our own custom values)
@ -992,21 +1027,6 @@ function KindleOasis:init()
return this:handleGyroEv(ev)
end
end
self.input.open(self.touch_dev)
self.input.open("/dev/input/by-path/platform-gpiokey.0-event")
-- get rotate dev by EV=d
local std_out = io.popen("grep -e 'Handlers\\|EV=' /proc/bus/input/devices | grep -B1 'EV=d' | grep -o 'event[0-9]'", "r")
if std_out then
local rotation_dev = std_out:read("*line")
std_out:close()
if rotation_dev then
self.input.open("/dev/input/"..rotation_dev)
end
end
self.input.open("fake_events")
end
-- HAL for gyro orientation switches (EV_ABS:ABS_PRESSURE (?!) w/ custom values to EV_MSC:MSC_GYRO w/ our own custom values)
@ -1118,21 +1138,6 @@ function KindleOasis2:init()
return this:handleGyroEv(ev)
end
end
self.input.open(self.touch_dev)
self.input.open("/dev/input/by-path/platform-gpio-keys-event")
-- Get accelerometer device by looking for EV=d
local std_out = io.popen("grep -e 'Handlers\\|EV=' /proc/bus/input/devices | grep -B1 'EV=d' | grep -o 'event[0-9]\\{1,2\\}'", "r")
if std_out then
local rotation_dev = std_out:read("*line")
std_out:close()
if rotation_dev then
self.input.open("/dev/input/"..rotation_dev)
end
end
self.input.open("fake_events")
end
function KindleOasis3:init()
@ -1201,21 +1206,6 @@ function KindleOasis3:init()
return this:handleGyroEv(ev)
end
end
self.input.open(self.touch_dev)
self.input.open("/dev/input/by-path/platform-gpio-keys-event")
-- Get accelerometer device by looking for EV=d
local std_out = io.popen("grep -e 'Handlers\\|EV=' /proc/bus/input/devices | grep -B1 'EV=d' | grep -o 'event[0-9]\\{1,2\\}'", "r")
if std_out then
local rotation_dev = std_out:read("*line")
std_out:close()
if rotation_dev then
self.input.open("/dev/input/"..rotation_dev)
end
end
self.input.open("fake_events")
end
function KindleBasic2:init()
@ -1229,9 +1219,6 @@ function KindleBasic2:init()
}
Kindle.init(self)
self.input.open(self.touch_dev)
self.input.open("fake_events")
end
function KindlePaperWhite4:init()
@ -1246,19 +1233,6 @@ function KindlePaperWhite4:init()
}
Kindle.init(self)
-- So, look for a goodix TS input device (c.f., #5110)...
local std_out = io.popen("grep -e 'Handlers\\|Name=' /proc/bus/input/devices | grep -A1 'goodix-ts' | grep -o 'event[0-9]'", "r")
if std_out then
local goodix_dev = std_out:read("*line")
std_out:close()
if goodix_dev then
self.touch_dev = "/dev/input/" .. goodix_dev
end
end
self.input.open(self.touch_dev)
self.input.open("fake_events")
end
function KindleBasic3:init()
@ -1278,29 +1252,6 @@ function KindleBasic3:init()
-- so we have to rely on contact lift detection via BTN_TOUCH:0,
-- c.f., https://github.com/koreader/koreader/issues/5070
self.input.snow_protocol = true
self.input.open(self.touch_dev)
self.input.open("fake_events")
end
local function findInputDevices()
-- Walk /sys/class/input and pick up any evdev input device with *any* EV_ABS capabilities
local devices = {}
for evdev in lfs.dir("/sys/class/input/") do
if evdev:match("event.*") then
local abs_cap = "/sys/class/input/" .. evdev .. "/device/capabilities/abs"
local f = io.open(abs_cap, "r")
if f then
local bitmap_str = f:read("l")
f:close()
if bitmap_str ~= "0" then
logger.info("Potential input device found at", evdev, "because of ABS caps:", bitmap_str)
table.insert(devices, "/dev/input/" .. evdev)
end
end
end
end
return devices
end
function KindlePaperWhite5:init()
@ -1319,25 +1270,10 @@ function KindlePaperWhite5:init()
self.screen:_MTK_ToggleFastMode(true)
Kindle.init(self)
-- Some HW/FW variants stash their input device without a by-path symlink...
if util.pathExists("/dev/input/by-path/platform-1001e000.i2c-event") then
self.touch_dev = "/dev/input/by-path/platform-1001e000.i2c-event"
self.input.open(self.touch_dev)
else
local devices = findInputDevices()
for _, touch in ipairs(devices) do
-- There should only be one match on the PW5 anyway...
self.touch_dev = touch
self.input.open(touch)
end
end
self.input.open("fake_events")
end
function KindleBasic4:init()
self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg}
-- TBD, assume PW5 for now
self.powerd = require("device/kindle/powerd"):new{
device = self,
fl_intensity_file = "/sys/class/backlight/fp9966-bl1/brightness",
@ -1351,20 +1287,6 @@ function KindleBasic4:init()
self.screen:_MTK_ToggleFastMode(true)
Kindle.init(self)
-- Some HW/FW variants stash their input device without a by-path symlink...
if util.pathExists("/dev/input/by-path/platform-1001e000.i2c-event") then
self.touch_dev = "/dev/input/by-path/platform-1001e000.i2c-event"
self.input.open(self.touch_dev)
else
local devices = findInputDevices()
for _, touch in ipairs(devices) do
-- There should only be one match on the PW5 anyway...
self.touch_dev = touch
self.input.open(touch)
end
end
self.input.open("fake_events")
end
function KindleScribe:init()
@ -1384,11 +1306,11 @@ function KindleScribe:init()
hall_file = "/sys/devices/platform/eink_hall/hall_enable",
}
Kindle.init(self)
-- Enable the so-called "fast" mode, so as to prevent the driver from silently promoting refreshes to REAGL.
self.screen:_MTK_ToggleFastMode(true)
Kindle.init(self)
--- @note The same quirks as on the Oasis 2 and 3 apply ;).
local haslipc, lipc = pcall(require, "liblipclua")
if haslipc and lipc then
@ -1399,14 +1321,10 @@ function KindleScribe:init()
logger.dbg("orientation_code =", orientation_code)
local rotation_mode = 0
if orientation_code then
if orientation_code == "U" then
if orientation_code == "U" or "L" then
rotation_mode = self.screen.DEVICE_ROTATED_UPRIGHT
elseif orientation_code == "R" then
rotation_mode = self.screen.DEVICE_ROTATED_CLOCKWISE
elseif orientation_code == "D" then
elseif orientation_code == "D" or "R" then
rotation_mode = self.screen.DEVICE_ROTATED_UPSIDE_DOWN
elseif orientation_code == "L" then
rotation_mode = self.screen.DEVICE_ROTATED_COUNTER_CLOCKWISE
end
end
if rotation_mode > 0 then
@ -1428,15 +1346,9 @@ function KindleScribe:init()
return this:handleGyroEv(ev)
end
end
-- Get accelerometer device
self.input.open("/dev/input/by-path/platform-11007000.i2c-event-joystick")
self.input.open(self.touch_dev)
self.input.open("fake_events")
-- Setup pen input
self.input.wacom_protocol = true
self.input.open("/dev/input/event4")
end
function KindleTouch:exit()
@ -1446,6 +1358,9 @@ function KindleTouch:exit()
end
if self.framework_lipc_handle then
-- Fixes missing *stock Amazon UI* screensavers on exiting out of "no framework" started KOReader
-- module was unloaded in frameworkStopped() function but wasn't (re)loaded on KOReader exit
self.framework_lipc_handle:set_string_property("com.lab126.blanket", "load", "screensaver")
self.framework_lipc_handle:close()
end

@ -15,6 +15,7 @@ local C = ffi.C
require("ffi/linux_fb_h")
require("ffi/linux_input_h")
require("ffi/posix_h")
require("ffi/fbink_input_h")
local function yes() return true end
local function no() return false end
@ -31,7 +32,7 @@ local function koboEnableWifi(toggle)
end
-- checks if standby is available on the device
local function checkStandby()
local function checkStandby(target_state)
logger.dbg("Kobo: checking if standby is possible ...")
local f = io.open("/sys/power/state")
if not f then
@ -40,11 +41,11 @@ local function checkStandby()
local mode = f:read()
f:close()
logger.dbg("Kobo: available power states:", mode)
if mode and mode:find("standby") then
logger.dbg("Kobo: standby state is supported")
if mode and mode:find(target_state) then
logger.dbg("Kobo: target standby state '" .. target_state .. "' is supported")
return yes
end
logger.dbg("Kobo: standby state is unsupported")
logger.dbg("Kobo: target standby state '" .. target_state .. "' is unsupported")
return no
end
@ -140,18 +141,19 @@ local Kobo = Generic:extend{
battery_sysfs = "/sys/class/power_supply/mc13892_bat",
-- Stable path to the NTX input device
ntx_dev = "/dev/input/event0",
ntx_fd = nil,
-- Stable path to the Touch input device
touch_dev = "/dev/input/event1",
-- Stable path to the Power Button input device
power_dev = nil,
-- Event code to use to detect contact pressure
pressure_event = nil,
-- Device features multiple CPU cores
isSMP = no,
-- Device supports "eclipse" waveform modes (i.e., optimized for nightmode).
hasEclipseWfm = no,
-- Device ships with various hardware revisions under the same device code, requiring automatic hardware detection...
-- Device ships with various hardware revisions under the same device code, requiring automatic hardware detection (PMIC & FL)...
automagic_sysfs = false,
-- The standard "standby" power state
standby_state = "standby",
unexpected_wakeup_count = 0,
}
@ -415,8 +417,6 @@ local KoboEuropa = Kobo:extend{
display_dpi = 227,
boot_rota = C.FB_ROTATE_CCW,
battery_sysfs = "/sys/class/power_supply/battery",
ntx_dev = "/dev/input/by-path/platform-ntx_event0-event",
touch_dev = "/dev/input/by-path/platform-0-0010-event",
isSMP = yes,
}
@ -446,8 +446,6 @@ local KoboCadmus = Kobo:extend{
battery_sysfs = "/sys/class/power_supply/battery",
hasAuxBattery = yes,
aux_battery_sysfs = "/sys/class/misc/cilix",
ntx_dev = "/dev/input/by-path/platform-ntx_event0-event",
touch_dev = "/dev/input/by-path/platform-0-0010-event",
isSMP = yes,
-- Much like the Libra 2, there are at least two different HW revisions, with different PMICs...
automagic_sysfs = true,
@ -501,7 +499,6 @@ local KoboGoldfinch = Kobo:extend{
nl_inverted = true,
},
battery_sysfs = "/sys/class/power_supply/battery",
power_dev = "/dev/input/by-path/platform-bd71828-pwrkey-event",
-- Board is eerily similar to the Libra 2, so, it inherits the same quirks...
-- c.f., https://github.com/koreader/koreader/issues/9552#issuecomment-1293000313
hasReliableMxcWaitFor = no,
@ -528,12 +525,77 @@ local KoboCondor = Kobo:extend{
nl_inverted = true,
},
battery_sysfs = "/sys/class/power_supply/bd71827_bat",
touch_dev = "/dev/input/by-path/platform-2-0010-event",
ntx_dev = "/dev/input/by-path/platform-ntx_event0-event",
power_dev = "/dev/input/by-path/platform-bd71828-pwrkey.6.auto-event",
isSMP = yes,
}
-- Kobo Libra Colour:
local KoboMonza = Kobo:extend{
model = "Kobo_monza",
isMTK = yes,
hasEclipseWfm = yes,
canToggleChargingLED = yes,
hasFrontlight = yes,
hasKeys = yes,
hasGSensor = yes,
display_dpi = 300,
pressure_event = C.ABS_MT_PRESSURE,
touch_mirrored_x = false,
touch_mirrored_y = true,
hasNaturalLight = yes,
frontlight_settings = {
frontlight_white = "/sys/class/backlight/mxc_msp430.0/brightness",
frontlight_mixer = "/sys/class/backlight/lm3630a_led/color",
nl_min = 0,
nl_max = 10,
nl_inverted = true,
},
battery_sysfs = "/sys/class/power_supply/bd71827_bat",
isSMP = yes,
hasColorScreen = yes,
}
-- Kobo Clara B/W:
local KoboSpaBW = Kobo:extend{
model = "Kobo_spaBW",
isMTK = yes,
hasEclipseWfm = yes,
canToggleChargingLED = yes,
hasFrontlight = yes,
touch_snow_protocol = true,
display_dpi = 300,
hasNaturalLight = yes,
frontlight_settings = {
frontlight_white = "/sys/class/backlight/mxc_msp430.0/brightness",
frontlight_mixer = "/sys/class/backlight/lm3630a_led/color",
nl_min = 0,
nl_max = 10,
nl_inverted = true,
},
battery_sysfs = "/sys/class/power_supply/bd71827_bat",
}
-- Kobo Clara Colour:
local KoboSpaColour = Kobo:extend{
model = "Kobo_spaColour",
isMTK = yes,
hasEclipseWfm = yes,
canToggleChargingLED = yes,
hasFrontlight = yes,
touch_snow_protocol = true,
display_dpi = 300,
hasNaturalLight = yes,
frontlight_settings = {
frontlight_white = "/sys/class/backlight/mxc_msp430.0/brightness",
frontlight_mixer = "/sys/class/backlight/lm3630a_led/color",
nl_min = 0,
nl_max = 10,
nl_inverted = true,
},
battery_sysfs = "/sys/class/power_supply/bd71827_bat",
isSMP = yes,
hasColorScreen = yes,
}
function Kobo:setupChargingLED()
if G_reader_settings:nilOrTrue("enable_charging_led") then
if self:hasAuxBattery() and self.powerd:isAuxBatteryConnected() then
@ -553,7 +615,7 @@ function Kobo:getKeyRepeat()
self.key_repeat = ffi.new("unsigned int[?]", C.REP_CNT)
if C.ioctl(self.ntx_fd, C.EVIOCGREP, self.key_repeat) < 0 then
local err = ffi.errno()
logger.warn("Device:getKeyRepeat: EVIOCGREP ioctl failed:", ffi.string(C.strerror(err)))
logger.warn("Device:getKeyRepeat: EVIOCGREP ioctl on fd", self.ntx_fd, "failed:", ffi.string(C.strerror(err)))
return false
else
logger.dbg("Key repeat is set up to repeat every", self.key_repeat[C.REP_PERIOD], "ms after a delay of", self.key_repeat[C.REP_DELAY], "ms")
@ -567,14 +629,14 @@ function Kobo:disableKeyRepeat()
local key_repeat = ffi.new("unsigned int[?]", C.REP_CNT)
if C.ioctl(self.ntx_fd, C.EVIOCSREP, key_repeat) < 0 then
local err = ffi.errno()
logger.warn("Device:disableKeyRepeat: EVIOCSREP ioctl failed:", ffi.string(C.strerror(err)))
logger.warn("Device:disableKeyRepeat: EVIOCSREP ioctl on fd", self.ntx_fd, "failed:", ffi.string(C.strerror(err)))
end
end
function Kobo:restoreKeyRepeat()
if C.ioctl(self.ntx_fd, C.EVIOCSREP, self.key_repeat) < 0 then
local err = ffi.errno()
logger.warn("Device:restoreKeyRepeat: EVIOCSREP ioctl failed:", ffi.string(C.strerror(err)))
logger.warn("Device:restoreKeyRepeat: EVIOCSREP ioctl on fd", self.ntx_fd, "failed:", ffi.string(C.strerror(err)))
end
end
@ -591,7 +653,7 @@ function Kobo:toggleKeyRepeat(toggle)
-- Check the current (kernel) state to know what to do
if C.ioctl(self.ntx_fd, C.EVIOCGREP, key_repeat) < 0 then
local err = ffi.errno()
logger.warn("Device:toggleKeyRepeat: EVIOCGREP ioctl failed:", ffi.string(C.strerror(err)))
logger.warn("Device:toggleKeyRepeat: EVIOCGREP ioctl on fd", self.ntx_fd, "failed:", ffi.string(C.strerror(err)))
return false
else
if key_repeat[C.REP_DELAY] == 0 and key_repeat[C.REP_PERIOD] == 0 then
@ -604,7 +666,7 @@ function Kobo:toggleKeyRepeat(toggle)
if C.ioctl(self.ntx_fd, C.EVIOCSREP, key_repeat) < 0 then
local err = ffi.errno()
logger.warn("Device:toggleKeyRepeat: EVIOCSREP ioctl failed:", ffi.string(C.strerror(err)))
logger.warn("Device:toggleKeyRepeat: EVIOCSREP ioctl on fd", self.ntx_fd, "failed:", ffi.string(C.strerror(err)))
return false
end
@ -637,8 +699,9 @@ function Kobo:init()
debug = logger.dbg,
is_always_portrait = self.isAlwaysPortrait(),
mxcfb_bypass_wait_for = mxcfb_bypass_wait_for,
no_cfa_post_processing = G_reader_settings:isTrue("no_cfa_post_processing"),
}
if self.screen.fb_bpp == 32 then
if self.screen.fb_bpp == 32 and not self:hasColorScreen() then
-- Ensure we decode images properly, as our framebuffer is BGRA...
logger.info("Enabling Kobo @ 32bpp BGR tweaks")
self.hasBGRFrameBuffer = yes
@ -669,6 +732,8 @@ function Kobo:init()
if util.pathExists("/sys/class/power_supply/battery") then
-- Newer devices (circa sunxi)
self.battery_sysfs = "/sys/class/power_supply/battery"
elseif util.fileExists("/sys/class/power_supply/bd71827_bat") then
self.battery_sysfs = "/sys/class/power_supply/bd71827_bat"
else
self.battery_sysfs = "/sys/class/power_supply/mc13892_bat"
end
@ -686,43 +751,6 @@ function Kobo:init()
self.frontlight_settings.frontlight_mixer = "/sys/class/backlight/tlc5947_bl/color"
end
end
-- Touch panel input
if util.fileExists("/dev/input/by-path/platform-2-0010-event") then
-- Elan (HWConfig TouchCtrl is ekth6) on i2c bus 2
self.touch_dev = "/dev/input/by-path/platform-2-0010-event"
elseif util.fileExists("/dev/input/by-path/platform-1-0010-event") then
-- Elan (HWConfig TouchCtrl is ekth6) on i2c bus 1
self.touch_dev = "/dev/input/by-path/platform-1-0010-event"
elseif util.fileExists("/dev/input/by-path/platform-0-0010-event") then
-- Elan (HWConfig TouchCtrl is ekth6) on i2c bus 0
self.touch_dev = "/dev/input/by-path/platform-0-0010-event"
else
self.touch_dev = "/dev/input/event1"
end
-- Physical buttons & synthetic NTX events
if util.fileExists("/dev/input/by-path/platform-gpio-keys-event") then
-- Libra 2 w/ a BD71828 PMIC
self.ntx_dev = "/dev/input/by-path/platform-gpio-keys-event"
elseif util.fileExists("/dev/input/by-path/platform-ntx_event0-event") then
-- MTK, sunxi & Mk. 7
self.ntx_dev = "/dev/input/by-path/platform-ntx_event0-event"
elseif util.fileExists("/dev/input/by-path/platform-mxckpd-event") then
-- circa Mk. 5 i.MX
self.ntx_dev = "/dev/input/by-path/platform-mxckpd-event"
else
self.ntx_dev = "/dev/input/event0"
end
-- Power button (this usually ends up in ntx_dev, except with some PMICs)
if util.fileExists("/dev/input/by-path/platform-bd71828-pwrkey-event") then
-- Libra 2 & Nia w/ a BD71828 PMIC
self.power_dev = "/dev/input/by-path/platform-bd71828-pwrkey-event"
elseif util.fileExists("/dev/input/by-path/platform-bd71828-pwrkey.4.auto-event") then
-- Sage w/ a BD71828 PMIC
self.power_dev = "/dev/input/by-path/platform-bd71828-pwrkey.4.auto-event"
end
end
-- NOTE: i.MX5 devices have a wonky RTC that doesn't like alarms set further away that UINT16_MAX seconds from now...
@ -759,10 +787,15 @@ function Kobo:init()
self.hasNaturalLightMixer = yes
end
-- Ditto
if self:isMk7() then
if self:isMk7() or self:isMTK() then
self.canHWDither = yes
end
-- Enable Kaleido waveform modes on supported devices
if self:hasColorScreen() and self:isMTK() then
self.hasKaleidoWfm = yes
end
-- NOTE: Devices with an AW99703 frontlight PWM controller feature a hardware smooth ramp when setting the frontlight intensity.
--- A side-effect of this behavior is that if you queue a series of intensity changes ending at 0,
--- it won't ramp *at all*, jumping straight to zero instead.
@ -771,6 +804,14 @@ function Kobo:init()
self.frontlight_settings.ramp_off_delay = 0.5
end
-- I don't know how this PWM controller behaves on earlier devices, but it's... not great here.
if self:hasNaturalLightMixer() and self:isMTK() and self.frontlight_settings.frontlight_mixer:find("lm3630a_led", 12, true) then
-- First, we need a delay between ioctls
self.frontlight_settings.ramp_delay = 0.025
-- Second, it *really* doesn't like being interleaved with screen refreshes
self.frontlight_settings.delay_ramp_start = true
end
self.powerd = require("device/kobo/powerd"):new{
device = self,
battery_sysfs = self.battery_sysfs,
@ -816,14 +857,41 @@ function Kobo:init()
-- And then handle the extra shenanigans if necessary.
self:initEventAdjustHooks()
-- Various HW Buttons, Switches & Synthetic NTX events
self.ntx_fd = self.input.open(self.ntx_dev)
-- Dedicated Power Button input device (if any)
if self.power_dev then
self.input.open(self.power_dev)
-- Auto-detect input devices (via FBInk's fbink_input_scan)
local ok, FBInkInput = pcall(ffi.load, "fbink_input")
if not ok then
-- NOP fallback for the testsuite...
FBInkInput = { fbink_input_scan = NOP }
end
local dev_count = ffi.new("size_t[1]")
-- We care about: the touchscreen, the stylus, the power button, the sleep cover, and pagination buttons
-- (and technically rotation events, but we'll get it with the device that provides the buttons on NTX).
-- We exclude keyboards to play nice with the ExternalKeyboard plugin, which will handle potential keyboards on its own.
local match_mask = bit.bor(C.INPUT_TOUCHSCREEN, C.INPUT_TABLET, C.INPUT_POWER_BUTTON, C.INPUT_SLEEP_COVER, C.INPUT_PAGINATION_BUTTONS)
local devices = FBInkInput.fbink_input_scan(match_mask, C.INPUT_KEYBOARD, 0, dev_count)
if devices ~= nil then
for i = 0, tonumber(dev_count[0]) - 1 do
local dev = devices[i]
if dev.matched then
-- We need to single out whichever device provides pagination buttons or sleep cover events, as we'll want to tweak key repeat there...
-- The first one will do, as it's extremely likely to be event0, and that's pretty fairly set in stone on NTX boards.
if (bit.band(dev.type, C.INPUT_PAGINATION_BUTTONS) ~= 0 or bit.band(dev.type, C.INPUT_SLEEP_COVER) ~= 0) and not self.ntx_fd then
self.ntx_fd = self.input.fdopen(tonumber(dev.fd), ffi.string(dev.path), ffi.string(dev.name))
else
self.input.fdopen(tonumber(dev.fd), ffi.string(dev.path), ffi.string(dev.name))
end
end
end
C.free(devices)
else
-- Auto-detection failed, warn and fall back to defaults
logger.warn("We failed to auto-detect the proper input devices, input handling may be inconsistent!")
-- Various HW Buttons, Switches & Synthetic NTX events
self.ntx_fd = self.input.open(self.ntx_dev)
-- Touch panel
self.input.open(self.touch_dev)
end
-- Touch panel
self.input.open(self.touch_dev)
-- NOTE: On devices with a gyro, there may be a dedicated input device outputting the raw accelerometer data
-- (3-Axis Orientation/Motion Detection).
-- We skip it because we don't need it (synthetic rotation change events are sent to the main ntx input device),
@ -844,9 +912,12 @@ function Kobo:init()
end
-- Detect the NTX charging LED sysfs knob
if util.pathExists("/sys/class/leds/bd71828-green-led") then
-- Standard Linux LED class, wheee!
self.charging_led_sysfs_knob = "/sys/class/leds/bd71828-green-led"
if util.pathExists("/sys/class/leds/LED") then
self.charging_led_sysfs_knob = "/sys/class/leds/LED/brightness"
elseif util.pathExists("/sys/class/leds/GLED") then
self.charging_led_sysfs_knob = "/sys/class/leds/GLED/brightness"
elseif util.pathExists("/sys/class/leds/bd71828-green-led") then
self.charging_led_sysfs_knob = "/sys/class/leds/bd71828-green-led/brightness"
elseif util.pathExists("/sys/devices/platform/ntx_led/lit") then
self.ntx_lit_sysfs_knob = "/sys/devices/platform/ntx_led/lit"
elseif util.pathExists("/sys/devices/platform/pmic_light.1/lit") then
@ -876,8 +947,15 @@ function Kobo:init()
-- Only enable a single core on startup
self:enableCPUCores(1)
self.canStandby = checkStandby()
if self.canStandby() and (self:isMk7() or self:isSunxi() or self:isMTK()) then
-- On MTK, the "standby" power state is unavailable, and Nickel instead uses "mem" (and /sys/power/mem_sleep doesn't exist either)
if self:isMTK() then
self.standby_state = "mem"
end
self.canStandby = checkStandby(self.standby_state)
if self.canStandby() and (self:isMk7() or self:isSunxi()) then
-- NOTE: Do *NOT* enable this on MTK. What happens if you do can only be described as "shit hits the fan".
-- (Nickel doesn't).
self.canPowerSaveWhileCharging = yes
end
@ -1182,7 +1260,7 @@ function Kobo:standby(max_duration)
-- WiFi toggle, but (almost) everywhere.
ffiUtil.usleep(90000) -- sleep 0.09s (0.08s would also work)
local ret = ffiUtil.writeToSysfs("standby", "/sys/power/state")
local ret = ffiUtil.writeToSysfs(self.standby_state, "/sys/power/state")
self.last_standby_time = time.boottime_or_realtime_coarse() - standby_time
self.total_standby_time = self.total_standby_time + self.last_standby_time
@ -1446,6 +1524,7 @@ function Kobo:_NTXChargingLEDToggle(toggle)
end
function Kobo:_LinuxChargingLEDToggle(toggle)
-- max_brightness usually says 255 for those, but 1 does the same (and matches Nickel's behavior)
ffiUtil.writeToSysfs(toggle and "1" or "0", self.charging_led_sysfs_knob)
end
@ -1678,6 +1757,12 @@ elseif codename == "goldfinch" then
return KoboGoldfinch
elseif codename == "condor" then
return KoboCondor
elseif codename == "monza" or codename == "monzaTolino" then
return KoboMonza
elseif codename == "spaBW" or codename == "spaTolinoBW" then
return KoboSpaBW
elseif codename == "spaColour" or codename == "spaTolinoColour" then
return KoboSpaColour
else
error("unrecognized Kobo model ".. codename .. " with device id " .. product_id)
end

@ -136,8 +136,12 @@ function KoboPowerD:init()
self.device.frontlight_settings = self.device.frontlight_settings or {}
-- Does this device require non-standard ramping behavior?
self.device.frontlight_settings.ramp_off_delay = self.device.frontlight_settings.ramp_off_delay or 0.0
--- @note: Newer devices appear to block slightly longer on FL ioctls/sysfs, so we only really need a delay on older devices.
--- @note: Newer devices (or at least some PWM controllers) appear to block slightly longer on FL ioctls/sysfs,
--- so we only really need a delay on older devices.
self.device.frontlight_settings.ramp_delay = self.device.frontlight_settings.ramp_delay or (self.device:hasNaturalLight() and 0.0 or 0.025)
-- Some PWM controllers *really* don't like being interleaved between screen refreshes,
-- so we delay the *start* of the ramp on these.
self.device.frontlight_settings.delay_ramp_start = self.device.frontlight_settings.delay_ramp_start or false
-- If this device has natural light, use the sysfs interface, and ioctl otherwise.
-- NOTE: On the Forma, nickel still appears to prefer using ntx_io to handle the FL,
@ -364,8 +368,17 @@ function KoboPowerD:turnOffFrontlightHW(done_callback)
if self.device.frontlight_settings.ramp_off_delay > 0.0 and self.fl_intensity <= 2 then
UIManager:scheduleIn(self.device.frontlight_settings.ramp_delay, self._endRampDown, self, self.fl_min, done_callback)
else
self:turnOffFrontlightRamp(self.fl_intensity, self.fl_min, done_callback)
self.fl_ramp_down_running = true
-- NOTE: Similarly, some controllers *really* don't like to be interleaved with screen refreshes,
-- so we wait until the next UI frame for the refreshes to go through first...
if self.device.frontlight_settings.delay_ramp_start then
UIManager:nextTick(function()
self:turnOffFrontlightRamp(self.fl_intensity, self.fl_min, done_callback)
self.fl_ramp_down_running = true
end)
else
self:turnOffFrontlightRamp(self.fl_intensity, self.fl_min, done_callback)
self.fl_ramp_down_running = true
end
end
end
else
@ -422,8 +435,16 @@ function KoboPowerD:turnOnFrontlightHW(done_callback)
-- NOTE: Match the ramp down behavior on devices with a ramp_off_delay: jump straight to 1 or 2% intensity.
UIManager:scheduleIn(self.device.frontlight_settings.ramp_delay, self._endRampUp, self, self.fl_intensity, done_callback)
else
self:turnOnFrontlightRamp(self.fl_min, self.fl_intensity, done_callback)
self.fl_ramp_up_running = true
-- Same deal as in turnOffFrontlightHW
if self.device.frontlight_settings.delay_ramp_start then
UIManager:nextTick(function()
self:turnOnFrontlightRamp(self.fl_min, self.fl_intensity, done_callback)
self.fl_ramp_up_running = true
end)
else
self:turnOnFrontlightRamp(self.fl_min, self.fl_intensity, done_callback)
self.fl_ramp_up_running = true
end
end
end
else

@ -56,9 +56,7 @@ local PocketBook = Generic:extend{
-- Works same as input.event_map, but for raw input EV_KEY translation
keymap = { [scan] = event },
}]]
-- Runtime state: whether raw input is actually used
--- @fixme: Never actually set anywhere?
is_using_raw_input = nil,
-- We'll nil raw_input at runtime if it cannot be used.
-- InkView may have started translating button codes based on rotation on newer devices...
-- That historically wasn't the case, hence this defaulting to false.
@ -242,7 +240,9 @@ function PocketBook:init()
-- NOTE: This all happens in ffi/input_pocketbook.lua
self._model_init()
if (not self.input.raw_input) or (not pcall(self.input.open, self.input, self.raw_input)) then
-- NOTE: This is the odd one out actually calling input.open as a *method*,
-- which the imp supports to get access to self.input.raw_input
if (not self.input.raw_input) or (not pcall(self.input.open, self.input)) then
inkview.OpenScreen()
-- Raw mode open failed (no permissions?), so we'll run the usual way.
-- Disable touch coordinate translation as inkview will do that.
@ -387,6 +387,14 @@ function PocketBook:initNetworkManager(NetworkMgr)
return band(inkview.QueryNetwork(), C.NET_CONNECTED) ~= 0
end
NetworkMgr.isWifiOn = NetworkMgr.isConnected
function NetworkMgr:isOnline()
-- Fail early if we don't even have a default route, otherwise we're
-- unlikely to be online and canResolveHostnames would never succeed
-- again because PocketBook's glibc parses /etc/resolv.conf on first
-- use only. See https://sourceware.org/bugzilla/show_bug.cgi?id=984
return NetworkMgr:hasDefaultRoute() and NetworkMgr:canResolveHostnames()
end
end
function PocketBook:getSoftwareVersion()
@ -420,6 +428,25 @@ function PocketBook:setEventHandlers(uimgr)
end
end
local function getBrowser()
if util.pathExists("/usr/bin/browser.app") then
return true, "/usr/bin/browser.app"
elseif util.pathExists("/ebrmain/bin/browser.app") then
return true, "/ebrmain/bin/browser.app"
end
return false
end
function PocketBook:canOpenLink()
return inkview.MultitaskingSupported() and getBrowser()
end
function PocketBook:openLink(link)
local found, bin = getBrowser()
if not found or not link or type(link) ~= "string" then return end
inkview.OpenBook(bin, link, 0)
end
-- Pocketbook HW rotation modes start from landsape, CCW
local function landscape_ccw() return {
1, 0, 3, 2, -- PORTRAIT, LANDSCAPE, PORTRAIT_180, LANDSCAPE_180
@ -598,7 +625,6 @@ local PocketBook632 = PocketBook:extend{
local PocketBook633 = PocketBook:extend{
model = "PBColor",
display_dpi = 300,
color_saturation = 1.5,
hasColorScreen = yes,
canHWDither = yes, -- Adjust color saturation with inkview
canUseCBB = no, -- 24bpp
@ -642,6 +668,24 @@ local PocketBook700 = PocketBook:extend{
inkview_translates_buttons = true,
}
-- PocketBook Era Color (PB700K3)
local PocketBook700K3 = PocketBook:extend{
model = "PBEraColor",
display_dpi = 300,
hasColorScreen = yes,
canHWDither = yes, -- Adjust color saturation with inkview
canUseCBB = no, -- 24bpp
isAlwaysPortrait = yes,
hasNaturalLight = yes,
-- c.f., https://github.com/koreader/koreader/issues/9556
inkview_translates_buttons = true,
}
function PocketBook700K3._fb_init(fb, finfo, vinfo)
-- Pocketbook Color Lux reports bits_per_pixel = 8, but actually uses an RGB24 framebuffer
vinfo.bits_per_pixel = 24
end
-- PocketBook InkPad 3 (740)
local PocketBook740 = PocketBook:extend{
model = "PBInkPad3",
@ -672,7 +716,6 @@ local PocketBook740_2 = PocketBook:extend{
local PocketBook741 = PocketBook:extend{
model = "PBInkPadColor",
display_dpi = 300,
color_saturation = 1.5,
hasColorScreen = yes,
canHWDither = yes, -- Adjust color saturation with inkview
canUseCBB = no, -- 24bpp
@ -689,7 +732,6 @@ end
local PocketBook743C = PocketBook:extend{
model = "PBInkPadColor2",
display_dpi = 300,
color_saturation = 1.5,
hasColorScreen = yes,
canHWDither = yes, -- Adjust color saturation with inkview
canUseCBB = no, -- 24bpp
@ -708,7 +750,6 @@ local PocketBook743K3 = PocketBook:extend{
model = "PBInkPadColor3",
display_dpi = 300,
viewport = Geom:new{x=3, y=2, w=1395, h=1864},
color_saturation = 1.5,
hasColorScreen = yes,
canHWDither = yes, -- Adjust color saturation with inkview
canUseCBB = no, -- 24bpp
@ -735,7 +776,6 @@ local PocketBook743G = PocketBook:extend{
local PocketBookColorLux = PocketBook:extend{
model = "PBColorLux",
display_dpi = 125,
color_saturation = 1.5,
hasColorScreen = yes,
canHWDither = yes, -- Adjust color saturation with inkview
canUseCBB = no, -- 24bpp
@ -776,83 +816,91 @@ local PocketBook1040 = PocketBook:extend{
logger.info('SoftwareVersion: ', PocketBook:getSoftwareVersion())
local codename = PocketBook:getDeviceModel()
local full_codename = PocketBook:getDeviceModel()
-- Pocketbook codenames are all over the place:
local codename = full_codename
-- "PocketBook 615 (PB615)"
codename = codename:match(" [(]([^()]+)[)]$") or codename
-- "PocketBook 615"
codename = codename:match("^PocketBook ([^ ].*)$") or codename
-- "PB615"
codename = codename:match("^PB(.+)$") or codename
if codename == "PocketBook 515" then
if codename == "515" then
return PocketBook515
elseif codename == "PB606" or codename == "PocketBook 606" then
elseif codename == "606" then
return PocketBook606
elseif codename == "PocketBook 611" then
elseif codename == "611" then
return PocketBook611
elseif codename == "PocketBook 613" then
elseif codename == "613" then
return PocketBook613
elseif codename == "PocketBook 614" or codename == "PocketBook 614W" then
elseif codename == "614" or codename == "614W" then
return PocketBook614W
elseif codename == "PB615" or codename == "PB615W" or
codename == "PocketBook 615" or codename == "PocketBook 615W" then
elseif codename == "615" or codename == "615W" then
return PocketBook615
elseif codename == "PB616" or codename == "PB616W" or
codename == "PocketBook 616" or codename == "PocketBook 616W" then
elseif codename == "616" or codename == "616W" then
return PocketBook616
elseif codename == "PB617" or codename == "PocketBook 617" then
elseif codename == "617" then
return PocketBook617
elseif codename == "PB618" then
elseif codename == "618" then
return PocketBook618
elseif codename == "PocketBook 622" then
elseif codename == "622" then
return PocketBook622
elseif codename == "PocketBook 623" then
elseif codename == "623" then
return PocketBook623
elseif codename == "PocketBook 624" then
elseif codename == "624" then
return PocketBook624
elseif codename == "PB625" then
elseif codename == "625" then
return PocketBook625
elseif codename == "PB626" or codename == "PB626(2)-TL3" or
codename == "PocketBook 626" then
elseif codename == "626" or codename == "626(2)-TL3" then
return PocketBook626
elseif codename == "PB627" then
elseif codename == "627" then
return PocketBook627
elseif codename == "PB628" then
elseif codename == "628" then
return PocketBook628
elseif codename == "PB629" then
elseif codename == "629" then
return PocketBook629
elseif codename == "PocketBook 630" then
elseif codename == "630" then
return PocketBook630
elseif codename == "PB631" or codename == "PocketBook 631" then
elseif codename == "631" then
return PocketBook631
elseif codename == "PB632" then
elseif codename == "632" then
return PocketBook632
elseif codename == "PB633" then
elseif codename == "633" then
return PocketBook633
elseif codename == "PB634" then
elseif codename == "634" then
return PocketBook634
elseif codename == "PB640" or codename == "PocketBook 640" then
elseif codename == "640" then
return PocketBook640
elseif codename == "PB641" then
elseif codename == "641" then
return PocketBook641
elseif codename == "PB650" or codename == "PocketBook 650" then
elseif codename == "650" then
return PocketBook650
elseif codename == "PB700" or codename == "PocketBook 700" then
elseif codename == "700" then
return PocketBook700
elseif codename == "PB740" then
elseif codename == "700K3" then
return PocketBook700K3
elseif codename == "740" then
return PocketBook740
elseif codename == "PB740-2" or codename == "PB740-3" then
elseif codename == "740-2" or codename == "740-3" then
return PocketBook740_2
elseif codename == "PB741" then
elseif codename == "741" then
return PocketBook741
elseif codename == "PB743C" then
elseif codename == "743C" then
return PocketBook743C
elseif codename == "PB743K3" then
elseif codename == "743K3" then
return PocketBook743K3
elseif codename == "PB743G" or codename == "PB743g" or codename == "PocketBook 743G" or codename == "PocketBook 743g" then
elseif codename == "743G" or codename == "743g" then
return PocketBook743G
elseif codename == "PocketBook 840" or codename == "Reader InkPad" then
elseif codename == "840" or codename == "Reader InkPad" then
return PocketBook840
elseif codename == "PB970" then
elseif codename == "970" then
return PocketBook970
elseif codename == "PB1040" then
elseif codename == "1040" then
return PocketBook1040
elseif codename == "PocketBook Color Lux" then
elseif codename == "Color Lux" then
return PocketBookColorLux
else
error("unrecognized PocketBook model " .. codename)
error("unrecognized PocketBook model " .. full_codename)
end

@ -68,6 +68,7 @@ local Device = Generic:extend{
hasBattery = SDL.getPowerInfo,
hasKeyboard = yes,
hasKeys = yes,
hasSymKey = os.getenv("DISABLE_TOUCH") == "1" and yes or no,
hasDPad = yes,
hasWifiToggle = no,
hasSeamlessWifiToggle = no,
@ -120,6 +121,12 @@ local Desktop = Device:extend{
hasExitOptions = notOSX,
}
local Flatpak = Device:extend{
model = "Flatpak",
isDesktop = yes,
canExternalDictLookup = no,
}
local Emulator = Device:extend{
model = "Emulator",
isEmulator = yes,
@ -436,6 +443,8 @@ io.write("Starting SDL in " .. SDL.getBasePath() .. "\n")
-------------- device probe ------------
if os.getenv("APPIMAGE") then
return AppImage
elseif os.getenv("FLATPAK") then
return Flatpak
elseif os.getenv("KO_MULTIUSER") then
return Desktop
elseif os.getenv("UBUNTU_APPLICATION_ISOLATION") then

@ -61,7 +61,7 @@ return {
[1073741893] = "F12", -- F[12]
[1073742049] = "Shift", -- left shift
[1073742053] = "Sym", -- right shift
[1073742053] = os.getenv("DISABLE_TOUCH") == "1" and "Sym" or "Shift", -- right shift
[1073742050] = "Alt", -- left alt
[1073742054] = "AA", -- right alt key
[1073741925] = "ContextMenu", -- Context menu key

@ -53,7 +53,8 @@ local settingsList = {
open_previous_document = {category="none", event="OpenLastDoc", title=_("Open previous document"), general=true},
history = {category="none", event="ShowHist", title=_("History"), general=true},
history_search = {category="none", event="SearchHistory", title=_("History search"), general=true},
favorites = {category="none", event="ShowColl", arg="favorites", title=_("Favorites"), general=true},
favorites = {category="none", event="ShowColl", title=_("Favorites"), general=true},
collections = {category="none", event="ShowCollList", title=_("Collections"), general=true},
filemanager = {category="none", event="Home", title=_("File browser"), general=true, separator=true},
----
dictionary_lookup = {category="none", event="ShowDictionaryLookup", title=_("Dictionary lookup"), general=true},
@ -65,7 +66,7 @@ local settingsList = {
----
-- Device
exit_screensaver = {category="none", event="ExitScreensaver", title=_("Exit screensaver"), device=true},
exit_screensaver = {category="none", event="ExitScreensaver", title=_("Exit sleep screen"), device=true},
start_usbms = {category="none", event="RequestUSBMS", title=_("Start USB storage"), device=true, condition=Device:canToggleMassStorage()},
suspend = {category="none", event="RequestSuspend", title=_("Suspend"), device=true, condition=Device:canSuspend()},
restart = {category="none", event="Restart", title=_("Restart KOReader"), device=true, condition=Device:canRestart()},
@ -82,6 +83,7 @@ local settingsList = {
----
toggle_key_repeat = {category="none", event="ToggleKeyRepeat", title=_("Toggle key repeat"), device=true, condition=Device:hasKeys() and Device:canKeyRepeat(), separator=true},
toggle_gsensor = {category="none", event="ToggleGSensor", title=_("Toggle accelerometer"), device=true, condition=Device:hasGSensor()},
lock_gsensor = {category="none", event="LockGSensor", title=_("Lock auto rotation to current orientation"), device=true, condition=Device:hasGSensor()},
toggle_rotation = {category="none", event="SwapRotation", title=_("Toggle orientation"), device=true},
invert_rotation = {category="none", event="InvertRotation", title=_("Invert rotation"), device=true},
iterate_rotation = {category="none", event="IterateRotation", title=_("Rotate by 90° CW"), device=true},
@ -133,12 +135,14 @@ local settingsList = {
open_next_document_in_folder = {category="none", event="OpenNextDocumentInFolder", title=_("Open next document in folder"), reader=true, separator=true},
----
show_config_menu = {category="none", event="ShowConfigMenu", title=_("Show bottom menu"), reader=true},
toggle_status_bar = {category="none", event="ToggleFooterMode", title=_("Toggle status bar"), reader=true, separator=true},
toggle_status_bar = {category="none", event="ToggleFooterMode", title=_("Toggle status bar"), reader=true},
toggle_chapter_progress_bar = {category="none", event="ToggleChapterProgressBar", title=_("Toggle chapter progress bar"), reader=true, separator=true},
----
prev_chapter = {category="none", event="GotoPrevChapter", title=_("Previous chapter"), reader=true},
next_chapter = {category="none", event="GotoNextChapter", title=_("Next chapter"), reader=true},
first_page = {category="none", event="GoToBeginning", title=_("First page"), reader=true},
last_page = {category="none", event="GoToEnd", title=_("Last page"), reader=true},
random_page = {category="none", event="GoToRandomPage", title=_("Random page"), reader=true},
page_jmp = {category="absolutenumber", event="GotoViewRel", min=-100, max=100, title=_("Turn pages"), reader=true},
go_to = {category="none", event="ShowGotoDialog", title=_("Go to page"), filemanager=true, reader=true},
skim = {category="none", event="ShowSkimtoDialog", title=_("Skim document"), reader=true},
@ -271,6 +275,7 @@ local dispatcher_menu_order = {
"history",
"history_search",
"favorites",
"collections",
"filemanager",
----
"dictionary_lookup",
@ -299,6 +304,7 @@ local dispatcher_menu_order = {
----
"toggle_key_repeat",
"toggle_gsensor",
"lock_gsensor",
"rotation_mode",
"toggle_rotation",
"invert_rotation",
@ -352,11 +358,13 @@ local dispatcher_menu_order = {
----
"show_config_menu",
"toggle_status_bar",
"toggle_chapter_progress_bar",
----
"prev_chapter",
"next_chapter",
"first_page",
"last_page",
"random_page",
"page_jmp",
"go_to",
"skim",
@ -710,7 +718,7 @@ function Dispatcher:_sortActions(caller, location, settings, touchmenu_instance)
local SortWidget = require("ui/widget/sortwidget")
local sort_widget
sort_widget = SortWidget:new{
title = _("Sort"),
title = _("Arrange actions"),
item_table = display_list,
callback = function()
if location[settings] and next(location[settings]) ~= nil then
@ -979,7 +987,7 @@ function Dispatcher:addSubMenu(caller, menu, location, settings)
end
menu[#menu].separator = true
table.insert(menu, {
text = _("Sort"),
text = _("Arrange actions"),
checked_func = function()
return location[settings] ~= nil
and location[settings].settings ~= nil

@ -38,6 +38,7 @@ local CreDocument = Document:extend{
authors = "doc.authors",
series = "doc.series.name",
series_index = "doc.series.number",
identifiers = "doc.identifiers",
},
-- Reasons for the fallback font ordering:
@ -115,6 +116,15 @@ end
function CreDocument:engineInit()
if not engine_initialized then
cre = require("libs/libkoreader-cre")
-- When forking to execute any stuff in a sub-process,
-- as that stuff may not care about properly closing
-- the document, skip cre.cpp finalizer to avoid any
-- assertion failure.
require("ffi/util").addRunInSubProcessAfterForkFunc("cre_skip_teardown", function()
cre.setSkipTearDown(true)
end)
-- initialize cache
self:cacheInit()
@ -173,6 +183,7 @@ function CreDocument:init()
self.default_css = "./data/epub.css"
if file_type == "fb2" or file_type == "fb3" then
self.default_css = "./data/fb2.css"
self.is_fb2 = true -- FB2 won't look good with any html-oriented stylesheet
end
-- This mode must be the same as the default one set as ReaderView.view_mode
@ -1367,6 +1378,11 @@ function CreDocument:setBatteryState(state)
self._document:setBatteryState(state)
end
function CreDocument:setPageInfoOverride(pageinfo)
logger.dbg("CreDocument: set page info", pageinfo)
self._document:setPageInfoOverride(pageinfo)
end
function CreDocument:isXPointerInCurrentPage(xp)
logger.dbg("CreDocument: check xpointer in current page", xp)
return self._document:isXPointerInCurrentPage(xp)

@ -201,6 +201,7 @@ function Document:getProps(cached_doc_metadata)
local language = makeNilIfEmpty(props.language or props.Language)
local keywords = makeNilIfEmpty(props.keywords or props.Keywords)
local description = makeNilIfEmpty(props.description or props.Description or props.subject)
local identifiers = makeNilIfEmpty(props.identifiers)
return {
title = title,
authors = authors,
@ -209,6 +210,7 @@ function Document:getProps(cached_doc_metadata)
language = language,
keywords = keywords,
description = description,
identifiers = identifiers,
}
end

@ -1064,6 +1064,10 @@ function KoptInterface:getWordFromReflowPosition(doc, boxes, pos)
local pageno = pos.page
local scratch_reflowed_page_boxes = self:getReflowedTextBoxesFromScratch(doc, pageno)
if not DEBUG.dassert(scratch_reflowed_page_boxes and next(scratch_reflowed_page_boxes) ~= nil, "scratch_reflowed_page_boxes shouldn't be nil/{}") then
return
end
local scratch_reflowed_word_box = self:getWordFromBoxes(scratch_reflowed_page_boxes, pos)
local reflowed_page_boxes = self:getReflowedTextBoxes(doc, pageno)
@ -1237,8 +1241,15 @@ function KoptInterface:getTextFromReflowPositions(doc, native_boxes, pos0, pos1)
local reflowed_page_boxes = self:getReflowedTextBoxes(doc, pageno)
local scratch_reflowed_word_box0 = self:getWordFromBoxes(scratch_reflowed_page_boxes, pos0)
if not DEBUG.dassert(scratch_reflowed_word_box0 and next(scratch_reflowed_word_box0) ~= nil, "scratch_reflowed_word_box0 shouldn't be nil/{}") then
return
end
local reflowed_word_box0 = self:getWordFromBoxes(reflowed_page_boxes, pos0)
local scratch_reflowed_word_box1 = self:getWordFromBoxes(scratch_reflowed_page_boxes, pos1)
if not DEBUG.dassert(scratch_reflowed_word_box1 and next(scratch_reflowed_word_box1) ~= nil, "scratch_reflowed_word_box1 shouldn't be nil/{}") then
return
end
local reflowed_word_box1 = self:getWordFromBoxes(reflowed_page_boxes, pos1)
local reflowed_pos_abs0 = scratch_reflowed_word_box0.box:center()

@ -142,12 +142,10 @@ function FontList:_readList(dir, mark)
-- See if we're interested
if file:sub(1, 1) == "." then return end
local file_type = file:lower():match(".+%.([^.]+)") or ""
if not font_exts[file_type] then return end
if not font_exts[file_type] or isInFontsBlacklist(file) then return end
-- Add it to the list
if not isInFontsBlacklist(file) then
table.insert(self.fontlist, path)
end
table.insert(self.fontlist, path)
-- And into cached info table
mark[path] = true

@ -58,7 +58,7 @@ Returns a translation.
local translation = _("A meaningful message.")
--]]
function GetText_mt.__call(gettext, msgid)
return gettext.translation[msgid] or gettext.wrapUntranslated(msgid)
return gettext.translation[msgid] and gettext.translation[msgid][0] or gettext.translation[msgid] or gettext.wrapUntranslated(msgid)
end
local function c_escape(what_full, what)
@ -275,6 +275,8 @@ function GetText_mt.__index.changeLang(new_lang)
-- unescape \\ or msgid won't match
s = s:gsub("\\\\", "\\")
data[what] = (data[what] or "") .. s
elseif what and s == "" and fuzzy then -- luacheck: ignore 542
-- Ignore the likes of msgid "" and msgstr ""
else
-- Don't save this fuzzy string and unset fuzzy for the next one.
fuzzy = false

@ -8,11 +8,14 @@ local util = require("util")
local collection_file = DataStorage:getSettingsDir() .. "/collection.lua"
local ReadCollection = {
coll = {},
coll = nil, -- hash table
coll_order = nil, -- hash table
last_read_time = 0,
default_collection_name = "favorites",
}
-- read, write
local function buildEntry(file, order, mandatory)
file = FFIUtil.realpath(file)
if not file then return end
@ -41,6 +44,7 @@ function ReadCollection:_read()
end
logger.dbg("ReadCollection: reading from collection file")
self.coll = {}
self.coll_order = {}
for coll_name, collection in pairs(collections.data) do
local coll = {}
for _, v in ipairs(collection) do
@ -50,14 +54,23 @@ function ReadCollection:_read()
end
end
self.coll[coll_name] = coll
if not collection.settings then -- favorites, first run
collection.settings = { order = 1 }
end
self.coll_order[coll_name] = collection.settings.order
end
end
function ReadCollection:write(collection_name)
local collections = LuaSettings:open(collection_file)
for coll_name in pairs(collections.data) do
if not self.coll[coll_name] then
collections:delSetting(coll_name)
end
end
for coll_name, coll in pairs(self.coll) do
if not collection_name or coll_name == collection_name then
local data = {}
local data = { settings = { order = self.coll_order[coll_name] } }
for _, item in pairs(coll) do
table.insert(data, { file = item.file, order = item.order })
end
@ -68,20 +81,32 @@ function ReadCollection:write(collection_name)
collections:flush()
end
function ReadCollection:getFileCollectionName(file, collection_name)
-- info
function ReadCollection:isFileInCollection(file, collection_name)
file = FFIUtil.realpath(file) or file
for coll_name, coll in pairs(self.coll) do
if not collection_name or coll_name == collection_name then
if coll[file] then
return coll_name, file
end
return self.coll[collection_name][file] and true or false
end
function ReadCollection:isFileInCollections(file)
file = FFIUtil.realpath(file) or file
for _, coll in pairs(self.coll) do
if coll[file] then
return true
end
end
return false
end
function ReadCollection:hasFile(file, collection_name)
local coll_name = self:getFileCollectionName(file, collection_name)
return coll_name and true or false
function ReadCollection:getCollectionsWithFile(file)
file = FFIUtil.realpath(file) or file
local collections = {}
for coll_name, coll in pairs(self.coll) do
if coll[file] then
collections[coll_name] = true
end
end
return collections
end
function ReadCollection:getCollectionMaxOrder(collection_name)
@ -94,61 +119,74 @@ function ReadCollection:getCollectionMaxOrder(collection_name)
return max_order
end
function ReadCollection:getOrderedCollection(collection_name)
local ordered_coll = {}
for _, item in pairs(self.coll[collection_name]) do
table.insert(ordered_coll, item)
end
table.sort(ordered_coll, function(v1, v2) return v1.order < v2.order end)
return ordered_coll
end
function ReadCollection:updateCollectionOrder(collection_name, ordered_coll)
local coll = self.coll[collection_name]
for i, item in ipairs(ordered_coll) do
coll[item.file].order = i
end
self:write(collection_name)
end
-- manage items
function ReadCollection:addItem(file, collection_name)
collection_name = collection_name or self.default_collection_name
local max_order = self:getCollectionMaxOrder(collection_name)
local item = buildEntry(file, max_order + 1)
self.coll[collection_name][item.file] = item
self:write(collection_name)
end
function ReadCollection:addItems(files, collection_name) -- files = { filepath = true, }
collection_name = collection_name or self.default_collection_name
local coll = self.coll[collection_name]
local max_order = self:getCollectionMaxOrder(collection_name)
local do_write
for file in pairs(files) do
if not self:hasFile(file) then
max_order = max_order + 1
local item = buildEntry(file, max_order)
coll[item.file] = item
do_write = true
function ReadCollection:addRemoveItemMultiple(file, collections_to_add)
file = FFIUtil.realpath(file) or file
for coll_name, coll in pairs(self.coll) do
if collections_to_add[coll_name] then
if not coll[file] then
local max_order = self:getCollectionMaxOrder(coll_name)
coll[file] = buildEntry(file, max_order + 1)
end
else
if coll[file] then
coll[file] = nil
end
end
end
if do_write then
self:write(collection_name)
self:write()
end
function ReadCollection:addItemsMultiple(files, collections_to_add)
for file in pairs(files) do
file = FFIUtil.realpath(file) or file
for coll_name in pairs(collections_to_add) do
local coll = self.coll[coll_name]
if not coll[file] then
local max_order = self:getCollectionMaxOrder(coll_name)
coll[file] = buildEntry(file, max_order + 1)
end
end
end
self:write()
end
function ReadCollection:removeItem(file, collection_name, no_write)
local coll_name, file_name = self:getFileCollectionName(file, collection_name)
if coll_name then
self.coll[coll_name][file_name] = nil
if not no_write then
self:write(coll_name)
function ReadCollection:removeItem(file, collection_name, no_write) -- FM: delete file; FMColl: remove file
file = FFIUtil.realpath(file) or file
if collection_name then
if self.coll[collection_name][file] then
self.coll[collection_name][file] = nil
if not no_write then
self:write(collection_name)
end
return true
end
else
local do_write
for _, coll in pairs(self.coll) do
if coll[file] then
coll[file] = nil
do_write = true
end
end
if do_write then
if not no_write then
self:write()
end
return true
end
return true
end
end
function ReadCollection:removeItems(files) -- files = { filepath = true, }
function ReadCollection:removeItems(files) -- FM: delete files
local do_write
for file in pairs(files) do
if self:removeItem(file, nil, true) then
@ -160,12 +198,12 @@ function ReadCollection:removeItems(files) -- files = { filepath = true, }
end
end
function ReadCollection:removeItemsByPath(path)
function ReadCollection:removeItemsByPath(path) -- FM: delete folder
local do_write
for coll_name, coll in pairs(self.coll) do
for file_name in pairs(coll) do
if util.stringStartsWith(file_name, path) then
self.coll[coll_name][file_name] = nil
coll[file_name] = nil
do_write = true
end
end
@ -185,21 +223,29 @@ function ReadCollection:_updateItem(coll_name, file_name, new_filepath, new_path
coll[item.file] = item
end
function ReadCollection:updateItem(file, new_filepath)
local coll_name, file_name = self:getFileCollectionName(file)
if coll_name then
self:_updateItem(coll_name, file_name, new_filepath)
self:write(coll_name)
function ReadCollection:updateItem(file, new_filepath) -- FM: rename file, move file
file = FFIUtil.realpath(file) or file
local do_write
for coll_name, coll in pairs(self.coll) do
if coll[file] then
self:_updateItem(coll_name, file, new_filepath)
do_write = true
end
end
if do_write then
self:write()
end
end
function ReadCollection:updateItems(files, new_path) -- files = { filepath = true, }
function ReadCollection:updateItems(files, new_path) -- FM: move files
local do_write
for file in pairs(files) do
local coll_name, file_name = self:getFileCollectionName(file)
if coll_name then
self:_updateItem(coll_name, file_name, nil, new_path)
do_write = true
file = FFIUtil.realpath(file) or file
for coll_name, coll in pairs(self.coll) do
if coll[file] then
self:_updateItem(coll_name, file, nil, new_path)
do_write = true
end
end
end
if do_write then
@ -207,7 +253,7 @@ function ReadCollection:updateItems(files, new_path) -- files = { filepath = tru
end
end
function ReadCollection:updateItemsByPath(path, new_path)
function ReadCollection:updateItemsByPath(path, new_path) -- FM: rename folder, move folder
local len = #path
local do_write
for coll_name, coll in pairs(self.coll) do
@ -223,6 +269,58 @@ function ReadCollection:updateItemsByPath(path, new_path)
end
end
function ReadCollection:getOrderedCollection(collection_name)
local ordered_coll = {}
for _, item in pairs(self.coll[collection_name]) do
table.insert(ordered_coll, item)
end
table.sort(ordered_coll, function(v1, v2) return v1.order < v2.order end)
return ordered_coll
end
function ReadCollection:updateCollectionOrder(collection_name, ordered_coll)
local coll = self.coll[collection_name]
for i, item in ipairs(ordered_coll) do
coll[item.file].order = i
end
self:write(collection_name)
end
-- manage collections
function ReadCollection:addCollection(coll_name)
local max_order = 0
for _, order in pairs(self.coll_order) do
if max_order < order then
max_order = order
end
end
self.coll_order[coll_name] = max_order + 1
self.coll[coll_name] = {}
self:write(coll_name)
end
function ReadCollection:renameCollection(coll_name, new_name)
self.coll_order[new_name] = self.coll_order[coll_name]
self.coll[new_name] = self.coll[coll_name]
self.coll_order[coll_name] = nil
self.coll[coll_name] = nil
self:write(new_name)
end
function ReadCollection:removeCollection(coll_name)
self.coll_order[coll_name] = nil
self.coll[coll_name] = nil
self:write()
end
function ReadCollection:updateCollectionListOrder(ordered_coll)
for i, item in ipairs(ordered_coll) do
self.coll_order[item.name] = i
end
self:write()
end
ReadCollection:_read()
return ReadCollection

@ -419,6 +419,13 @@ Further small adjustments can be done with 'Line Spacing' in the bottom menu.]])
},
{
title = _("Font size and families"),
{
id = "font_no_presentational_hints",
title = _("Ignore font related HTML presentational hints"),
description = _("Ignore HTML attributes that contribute to styles on the elements <body> (bgcolor, text…) and <font> (face, size, color…)."),
css = [[body, font { -cr-hint: no-presentational; }]],
separator = true,
},
{
id = "font_family_all_inherit",
title = _("Ignore publisher font families"),
@ -564,6 +571,13 @@ body, h1, h2, h3, h4, h5, h6, div, li, td, th { text-indent: 0 !important; }
title = _("Tables, links, images"),
{
title = _("Tables"),
{
id = "table_no_presentational_hints",
title = _("Ignore tables related HTML presentational hints"),
description = _("Ignore HTML attributes that contribute to styles on the <table> element and its sub-elements (ie. align, valign, frame, rules, border, cellpadding, cellspacing…)."),
css = [[table, caption, colgroup, col, thead, tbody, tfoot, tr, td, th { -cr-hint: no-presentational; }]],
separator = true,
},
{
id = "table_full_width",
title = _("Full-width tables"),

@ -0,0 +1,57 @@
local cs_keyboard = require("util").tableDeepCopy(require("ui/data/keyboardlayouts/sk_keyboard"))
local keys = cs_keyboard.keys
keys[1][2][1] = {
"2",
north = "ě",
northeast = "Ě",
east = "~",
southeast = "/",
south = "@",
southwest = "https://",
west = "http://",
northwest = "Ĺ",
alt_label = "ě",
}
keys[1][2][2] = {
"ě",
north = "2",
northeast = "Ě",
east = "~",
southeast = "/",
south = "@",
southwest = "https://",
west = "http://",
northwest = "ĺ",
alt_label = "2",
}
keys[1][5][1] = {
"5",
north = "ř",
northeast = "Ř",
east = "¾",
southeast = "",
south = "%",
southwest = "",
west = "",
northwest = "Ŕ",
alt_label = "ř",
}
keys[1][5][2] = {
"ř",
north = "5",
northeast = "Ř",
east = "¼",
southeast = "",
south = "%",
southwest = "",
west = "½",
northwest = "ŕ",
alt_label = "5",
}
keys[5][4].label = "mezera"
return cs_keyboard

@ -10,7 +10,7 @@ local util = require("util")
local _ = require("gettext")
-- Date at which the last migration snippet was added
local CURRENT_MIGRATION_DATE = 20231217
local CURRENT_MIGRATION_DATE = 20240408
-- Retrieve the date of the previous migration, if any
local last_migration_date = G_reader_settings:readSetting("last_migration_date", 0)
@ -647,5 +647,16 @@ if last_migration_date < 20231217 then
end
end
-- 20240408, drop sleep screen/screensaver image_file setting in favor of document cover
if last_migration_date < 20240408 then
logger.info("Performing one-time migration for 20240408")
local image_file = G_reader_settings:readSetting("screensaver_type") == "image_file" and G_reader_settings:readSetting("screensaver_image")
if image_file then
G_reader_settings:saveSetting("screensaver_type", "document_cover")
G_reader_settings:saveSetting("screensaver_document_cover", image_file)
end
end
-- We're done, store the current migration date
G_reader_settings:saveSetting("last_migration_date", CURRENT_MIGRATION_DATE)

@ -285,10 +285,6 @@ if Device:isTouchDevice() then
}
common_settings.screen_disable_double_tab = require("ui/elements/screen_disable_double_tap_table")
common_settings.menu_activate = require("ui/elements/menu_activate")
common_settings.keyboard_layout = {
text = _("Keyboard"),
sub_item_table = require("ui/elements/menu_keyboard_layout"),
}
end
-- NOTE: Allow disabling color if it's mistakenly enabled on a Grayscale screen (after a settings import?)
@ -715,6 +711,11 @@ common_settings.device = {
text = _("Device"),
}
common_settings.keyboard_layout = {
text = _("Keyboard"),
sub_item_table = require("ui/elements/menu_keyboard_layout"),
}
common_settings.font_ui_fallbacks = require("ui/elements/font_ui_fallbacks")
common_settings.units = {

@ -168,6 +168,7 @@ local order = {
"history",
"open_last_document",
"----------------------------",
"favorites",
"collections",
"----------------------------",
"mass_storage_actions", -- if Device:canToggleMassStorage()

@ -50,13 +50,13 @@ local genFallbackCandidates = function()
end
end
local more_info_text = _([[
If some book titles, dictionary entries and such are not displayed well but shown as or <EFBFBD><EFBFBD>, it may be necessary to download the required fonts for those languages. They can then be enabled as additional UI fallback fonts.
local more_info_text = T(_([[
If some book titles, dictionary entries and such are not displayed well but shown as %1 or %2, it may be necessary to download the required fonts for those languages. They can then be enabled as additional UI fallback fonts.
Fonts for many languages can be downloaded at:
https://fonts.google.com/noto
Only fonts named "Noto Sans xyz" or "Noto Sans xyz UI" (regular, not bold nor italic, not Serif) will be available in this menu. However, bold fonts will be used if their corresponding regular fonts exist.]])
Only fonts named "Noto Sans xyz" or "Noto Sans xyz UI" (regular, not bold nor italic, not Serif) will be available in this menu. However, bold fonts will be used if their corresponding regular fonts exist.]]), "￾￾", "<EFBFBD><EFBFBD>")
local getSubMenuItems = function()
genFallbackCandidates()

@ -71,15 +71,17 @@ You can set how many lines are shown.]]),
})
local page_overlap_styles = {
arrow = _("Arrow"),
dim = _("Gray out"),
line = _("Horizontal line"),
{_("Arrow"), "arrow"},
{_("Gray out"), "dim"},
{_("Solid line"), "line"},
{_("Dashed line"), "dashed_line"},
}
for k, v in FFIUtil.orderedPairs(page_overlap_styles) do
for _, v in ipairs(page_overlap_styles) do
local style_text, style = unpack(v)
table.insert(PageOverlap.sub_item_table, {
text_func = function()
local text = v
if G_reader_settings:readSetting("page_overlap_style") == k then
local text = style_text
if G_reader_settings:readSetting("page_overlap_style") == style then
text = text .. ""
end
return text
@ -88,14 +90,14 @@ for k, v in FFIUtil.orderedPairs(page_overlap_styles) do
return ReaderUI.instance.view:isOverlapAllowed() and ReaderUI.instance.view.page_overlap_enable
end,
checked_func = function()
return ReaderUI.instance.view.page_overlap_style == k
return ReaderUI.instance.view.page_overlap_style == style
end,
radio = true,
callback = function()
ReaderUI.instance.view.page_overlap_style = k
ReaderUI.instance.view.page_overlap_style = style
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:saveSetting("page_overlap_style", k)
G_reader_settings:saveSetting("page_overlap_style", style)
touchmenu_instance:updateItems()
end,
})

@ -35,6 +35,7 @@ local order = {
"----------------------------",
"toc_items_per_page",
"toc_items_font_size",
"toc_items_show_chapter_length",
"toc_items_with_dots",
"----------------------------",
"toc_alt_toc",
@ -226,6 +227,7 @@ local order = {
"history",
"open_previous_document",
"----------------------------",
"favorites",
"collections",
"----------------------------",
"book_status",

@ -57,8 +57,7 @@ If you need to do so, you'll have to use the UI toggles.]]),
return G_reader_settings:isTrue("input_lock_gsensor")
end,
callback = function()
G_reader_settings:flipNilOrFalse("input_lock_gsensor")
Device:lockGSensor(G_reader_settings:isTrue("input_lock_gsensor"))
UIManager:broadcastEvent(Event:new("LockGSensor"))
end,
})
end

@ -26,64 +26,28 @@ local function genMenuItem(text, setting, value, enabled_func, separator)
separator = separator,
}
end
return {
genMenuItem(_("Use last book's cover as screensaver"), "screensaver_type", "cover", hasLastFile),
genMenuItem(_("Use book status as screensaver"), "screensaver_type", "bookstatus", hasLastFile),
genMenuItem(_("Use random image from folder as screensaver"), "screensaver_type", "random_image"),
genMenuItem(_("Use document cover as screensaver"), "screensaver_type", "document_cover"),
genMenuItem(_("Use image as screensaver"), "screensaver_type", "image_file"),
genMenuItem(_("Use reading progress as screensaver"), "screensaver_type", "readingprogress", isReaderProgressEnabled),
genMenuItem(_("Leave screen as-is"), "screensaver_type", "disable", nil, true),
-- separator
{
text = _("Add message to screensaver"),
checked_func = function()
return G_reader_settings:isTrue("screensaver_show_message")
end,
callback = function()
G_reader_settings:toggle("screensaver_show_message")
end,
separator = true,
},
-- separator
{
text = _("Settings"),
text = _("Wallpaper"),
sub_item_table = {
genMenuItem(_("Show book cover on sleep screen"), "screensaver_type", "cover", hasLastFile),
genMenuItem(_("Show custom image or cover on sleep screen"), "screensaver_type", "document_cover"),
genMenuItem(_("Show random image from folder on sleep screen"), "screensaver_type", "random_image"),
genMenuItem(_("Show reading progress on sleep screen"), "screensaver_type", "readingprogress", isReaderProgressEnabled),
genMenuItem(_("Show book status on sleep screen"), "screensaver_type", "bookstatus", hasLastFile),
genMenuItem(_("Leave screen as-is"), "screensaver_type", "disable", nil, true),
separator = true,
{
text = _("Screensaver folder"),
keep_menu_open = true,
callback = function()
Screensaver:chooseFolder()
end,
},
{
text = _("Screensaver image"),
keep_menu_open = true,
callback = function()
Screensaver:chooseFile()
text = _("Border fill"),
enabled_func = function()
return G_reader_settings:readSetting("screensaver_type") == "cover"
or G_reader_settings:readSetting("screensaver_type") == "document_cover"
or G_reader_settings:readSetting("screensaver_type") == "random_image"
end,
},
{
text = _("Document cover"),
keep_menu_open = true,
callback = function()
Screensaver:chooseFile(true)
end,
},
{
text = _("Screensaver message"),
keep_menu_open = true,
callback = function()
Screensaver:setMessage()
end,
},
{
text = _("Covers and images settings"),
sub_item_table = {
genMenuItem(_("Black background"), "screensaver_img_background", "black"),
genMenuItem(_("White background"), "screensaver_img_background", "white"),
genMenuItem(_("Leave background as-is"), "screensaver_img_background", "none", nil, true),
genMenuItem(_("Black fill"), "screensaver_img_background", "black"),
genMenuItem(_("White fill"), "screensaver_img_background", "white"),
genMenuItem(_("No fill"), "screensaver_img_background", "none", nil, true),
-- separator
{
text_func = function()
@ -91,7 +55,7 @@ return {
if G_reader_settings:isTrue("screensaver_stretch_images") and percentage then
return T(_("Stretch to fit screen (with limit: %1 %)"), percentage)
end
return _("Stretch to fit screen")
return _("Stretch cover to fit screen")
end,
checked_func = function()
return G_reader_settings:isTrue("screensaver_stretch_images")
@ -103,38 +67,102 @@ return {
},
},
{
text = _("Message settings"),
text = _("Postpone screen update after wake-up"),
sub_item_table = {
genMenuItem(_("No delay"), "screensaver_delay", "disable"),
genMenuItem(_("1 second"), "screensaver_delay", "1"),
genMenuItem(_("3 seconds"), "screensaver_delay", "3"),
genMenuItem(_("5 seconds"), "screensaver_delay", "5"),
genMenuItem(_("Until a tap"), "screensaver_delay", "tap"),
genMenuItem(_("Until 'exit sleep screen' gesture"), "screensaver_delay", "gesture"),
},
},
{
text = _("Custom images"),
enabled_func = function()
return G_reader_settings:readSetting("screensaver_type") == "random_image"
or G_reader_settings:readSetting("screensaver_type") == "document_cover"
end,
sub_item_table = {
genMenuItem(_("Black background behind message"), "screensaver_msg_background", "black"),
genMenuItem(_("White background behind message"), "screensaver_msg_background", "white"),
genMenuItem(_("Leave background as-is behind message"), "screensaver_msg_background", "none", nil, true),
-- separator
genMenuItem(_("Message position: top"), "screensaver_message_position", "top"),
genMenuItem(_("Message position: middle"), "screensaver_message_position", "middle"),
genMenuItem(_("Message position: bottom"), "screensaver_message_position", "bottom", nil, true),
-- separator
{
text = _("Hide reboot/poweroff message"),
checked_func = function()
return G_reader_settings:isTrue("screensaver_hide_fallback_msg")
text = _("Select image or document cover"),
enabled_func = function()
return G_reader_settings:readSetting("screensaver_type") == "document_cover"
end,
keep_menu_open = true,
callback = function()
G_reader_settings:toggle("screensaver_hide_fallback_msg")
Screensaver:chooseFile()
end,
},
{
text = _("Select random image folder"),
enabled_func = function()
return G_reader_settings:readSetting("screensaver_type") == "random_image"
end,
keep_menu_open = true,
callback = function()
Screensaver:chooseFolder()
end,
},
},
},
},
},
{
text = _("Sleep screen message"),
sub_item_table = {
{
text = _("Add custom message to sleep screen"),
checked_func = function()
return G_reader_settings:isTrue("screensaver_show_message")
end,
callback = function()
G_reader_settings:toggle("screensaver_show_message")
end,
separator = true,
},
{
text = _("Edit sleep screen message"),
enabled_func = function()
return G_reader_settings:isTrue("screensaver_show_message")
end,
keep_menu_open = true,
callback = function()
Screensaver:setMessage()
end,
},
{
text = _("Background fill"),
help_text = _("This option will only become available, if you have selected 'Leave screen as-is' as wallpaper and have 'Sleep screen message' on."),
enabled_func = function()
return G_reader_settings:readSetting("screensaver_type") == "disable" and G_reader_settings:isTrue("screensaver_show_message")
end,
sub_item_table = {
genMenuItem(_("Black fill"), "screensaver_msg_background", "black"),
genMenuItem(_("White fill"), "screensaver_msg_background", "white"),
genMenuItem(_("No fill"), "screensaver_msg_background", "none", nil, true),
},
},
{
text = _("Keep the screensaver on screen after wakeup"),
text = _("Message position"),
enabled_func = function()
return G_reader_settings:isTrue("screensaver_show_message")
end,
sub_item_table = {
genMenuItem(_("Disable"), "screensaver_delay", "disable"),
genMenuItem(_("For 1 second"), "screensaver_delay", "1"),
genMenuItem(_("For 3 second"), "screensaver_delay", "3"),
genMenuItem(_("For 5 second"), "screensaver_delay", "5"),
genMenuItem(_("Until a tap"), "screensaver_delay", "tap"),
genMenuItem(_("Until 'Exit screensaver' gesture"), "screensaver_delay", "gesture"),
genMenuItem(_("Top"), "screensaver_message_position", "top"),
genMenuItem(_("Middle"), "screensaver_message_position", "middle"),
genMenuItem(_("Bottom"), "screensaver_message_position", "bottom", nil, true),
},
},
{
text = _("Hide reboot/poweroff message"),
checked_func = function()
return G_reader_settings:isTrue("screensaver_hide_fallback_msg")
end,
callback = function()
G_reader_settings:toggle("screensaver_hide_fallback_msg")
end,
},
},
},
}

@ -6,6 +6,7 @@ local Language = {
language_names = {
C = "English",
en = "English",
en_GB = "English (United Kingdom)",
ca = "Catalá",
cs = "Čeština",
da = "Dansk",
@ -118,6 +119,7 @@ function Language:getLangMenuTable()
-- NOTE: language with no translation are commented out for now
sub_item_table = {
self:genLanguageSubItem("C"),
self:genLanguageSubItem("en_GB"),
self:genLanguageSubItem("ca"),
self:genLanguageSubItem("cs"),
self:genLanguageSubItem("de"),
@ -138,7 +140,7 @@ function Language:getLangMenuTable()
--self:genLanguageSubItem("pl_PL"),
self:genLanguageSubItem("pt_PT"),
self:genLanguageSubItem("pt_BR"),
--self:genLanguageSubItem("ro"),
self:genLanguageSubItem("ro"),
self:genLanguageSubItem("ro_MD"),
self:genLanguageSubItem("sk"),
self:genLanguageSubItem("sv"),

@ -274,6 +274,48 @@ function NetworkMgr:ifHasAnAddress()
return ok
end
-- The socket API equivalent of "ip route get 203.0.113.1 || ip route get 2001:db8::1".
--
-- These addresses are from special ranges reserved for documentation
-- (RFC 5737, RFC 3849) and therefore likely to just use the default route.
function NetworkMgr:hasDefaultRoute()
local socket = require("socket")
local s, ret, err
s, err = socket.udp()
if s == nil then
logger.err("NetworkMgr: socket.udp:", err)
return nil
end
ret, err = s:setpeername("203.0.113.1", "53")
if ret == nil then
-- Most likely "Network is unreachable", meaning there's no route to that address.
logger.dbg("NetworkMgr: socket.udp.setpeername:", err)
-- Try IPv6, may still succeed if this is an IPv6-only network.
ret, err = s:setpeername("2001:db8::1", "53")
if ret == nil then
-- Most likely "Network is unreachable", meaning there's no route to that address.
logger.dbg("NetworkMgr: socket.udp.setpeername:", err)
end
end
s:close()
-- If setpeername succeeded, we have a default route.
return ret ~= nil
end
function NetworkMgr:canResolveHostnames()
local socket = require("socket")
-- Microsoft uses `dns.msftncsi.com` for Windows, see
-- <https://technet.microsoft.com/en-us/library/ee126135#BKMK_How> for
-- more information. They also check whether <http://www.msftncsi.com/ncsi.txt>
-- returns `Microsoft NCSI`.
return socket.dns.toip("dns.msftncsi.com") ~= nil
end
-- Wrappers around turnOnWifi & turnOffWifi with proper Event signaling
function NetworkMgr:enableWifi(wifi_cb, connectivity_cb, connectivity_widget, interactive)
local status = self:requestToTurnOnWifi(wifi_cb, interactive)
@ -532,12 +574,7 @@ function NetworkMgr:isOnline()
return true
end
local socket = require("socket")
-- Microsoft uses `dns.msftncsi.com` for Windows, see
-- <https://technet.microsoft.com/en-us/library/ee126135#BKMK_How> for
-- more information. They also check whether <http://www.msftncsi.com/ncsi.txt>
-- returns `Microsoft NCSI`.
return socket.dns.toip("dns.msftncsi.com") ~= nil
return self:canResolveHostnames()
end
-- Update our cached network status

@ -16,6 +16,10 @@ local NetworkListener = EventListener:extend{
_activity_check_delay_seconds = nil,
}
if not Device:hasWifiToggle() then
return NetworkListener
end
local function enableWifi()
local toggle_im = InfoMessage:new{
text = _("Turning on Wi-Fi…"),
@ -173,11 +177,9 @@ end
function NetworkListener:onNetworkConnected()
logger.dbg("NetworkListener: onNetworkConnected")
if Device:hasWifiToggle() then
-- This is for the sake of events that don't emanate from NetworkMgr itself (e.g., the Emu)...
NetworkMgr:setWifiState(true)
NetworkMgr:setConnectionState(true)
end
-- This is for the sake of events that don't emanate from NetworkMgr itself (e.g., the Emu)...
NetworkMgr:setWifiState(true)
NetworkMgr:setConnectionState(true)
if not G_reader_settings:isTrue("auto_disable_wifi") then
return
@ -190,10 +192,8 @@ end
function NetworkListener:onNetworkDisconnected()
logger.dbg("NetworkListener: onNetworkDisconnected")
if Device:hasWifiToggle() then
NetworkMgr:setWifiState(false)
NetworkMgr:setConnectionState(false)
end
NetworkMgr:setWifiState(false)
NetworkMgr:setConnectionState(false)
NetworkListener:_unscheduleActivityCheck()
-- Reset NetworkMgr's beforeWifiAction marker

@ -3,6 +3,7 @@
local DataStorage = require("datastorage")
local FileConverter = require("apps/filemanager/filemanagerconverter")
local DocSettings = require("docsettings")
local Language = require("ui/language")
local Version = require("version")
local FFIUtil = require("ffi/util")
local T = FFIUtil.template
@ -257,6 +258,9 @@ function QuickStart:getQuickStart()
relpath = relpath .. dst
relpath = relpath:gsub("//", "/") -- make it prettier
quickstart_html = quickstart_html:gsub([[src="resources/]], [[src="]]..relpath..[[resources/]])
if Language:isLanguageRTL(language) then
quickstart_html = quickstart_html:gsub('<html>', '<html dir="rtl">')
end
-- Write the fixed HTML content
FileConverter:writeStringToFile(quickstart_html, quickstart_filename)
end

@ -148,7 +148,13 @@ function Screensaver:expandSpecial(message, fallback)
time_left_chapter = self:_calcAverageTimeForPages(ui.toc:getChapterPagesLeft(currentpage) or doc:getTotalPagesLeft(currentpage))
time_left_document = self:_calcAverageTimeForPages(doc:getTotalPagesLeft(currentpage))
end
percent = Math.round((currentpage * 100) / totalpages)
if currentpage == 1 then
percent = 0
elseif currentpage == totalpages then
percent = 100
else
percent = Math.round(Math.clamp(((currentpage * 100) / totalpages), 1, 99))
end
props = ui.doc_props
elseif DocSettings:hasSidecarFile(lastfile) then
-- If there's no ReaderUI instance, but the file has sidecar data, use that
@ -156,7 +162,13 @@ function Screensaver:expandSpecial(message, fallback)
totalpages = doc_settings:readSetting("doc_pages") or totalpages
percent = doc_settings:readSetting("percent_finished") or percent
currentpage = Math.round(percent * totalpages)
percent = Math.round(percent * 100)
if currentpage == 1 then
percent = 0
elseif currentpage == totalpages then
percent = 100
else
percent = Math.round(Math.clamp(percent * 100, 1, 99))
end
props = FileManagerBookInfo.extendProps(doc_settings:readSetting("doc_props"), lastfile)
-- Unable to set time_left_chapter and time_left_document without ReaderUI, so leave N/A
end
@ -261,26 +273,15 @@ function Screensaver:chooseFolder()
filemanagerutil.showChooseDialog(title_header, caller_callback, current_path)
end
function Screensaver:chooseFile(document_cover)
function Screensaver:chooseFile()
local title_header, current_path, file_filter, caller_callback
if document_cover then
title_header = _("Current screensaver document cover:")
current_path = G_reader_settings:readSetting("screensaver_document_cover")
file_filter = function(filename)
return DocumentRegistry:hasProvider(filename)
end
caller_callback = function(path)
G_reader_settings:saveSetting("screensaver_document_cover", path)
end
else
title_header = _("Current screensaver image:")
current_path = G_reader_settings:readSetting("screensaver_image")
file_filter = function(filename)
return DocumentRegistry:isImageFile(filename)
end
caller_callback = function(path)
G_reader_settings:saveSetting("screensaver_image", path)
end
title_header = _("Current sleep screen image or document cover:")
current_path = G_reader_settings:readSetting("screensaver_document_cover")
file_filter = function(filename)
return DocumentRegistry:hasProvider(filename)
end
caller_callback = function(path)
G_reader_settings:saveSetting("screensaver_document_cover", path)
end
filemanagerutil.showChooseDialog(title_header, caller_callback, current_path, nil, file_filter)
end
@ -313,9 +314,9 @@ function Screensaver:setMessage()
or self.default_screensaver_message
local input_dialog
input_dialog = InputDialog:new{
title = _("Screensaver message"),
title = _("Sleep screen message"),
description = _([[
Enter the message to be displayed by the screensaver. The following escape sequences can be used:
Enter a custom message to be displayed on the sleep screen. The following escape sequences are available:
%T title
%A author(s)
%S series
@ -394,7 +395,6 @@ end
function Screensaver:modeIsImage()
return self.screensaver_type == "cover"
or self.screensaver_type == "random_image"
or self.screensaver_type == "image_file"
end
function Screensaver:withBackground()
@ -446,9 +446,13 @@ function Screensaver:setup(event, event_message)
end
if not excluded then
if lastfile and lfs.attributes(lastfile, "mode") == "file" then
self.image = FileManagerBookInfo:getCoverImage(ui and ui.document, lastfile)
if self.image == nil then
self.screensaver_type = "random_image"
if DocumentRegistry:isImageFile(lastfile) then
self.image_file = lastfile
else
self.image = FileManagerBookInfo:getCoverImage(ui and ui.document, lastfile)
if self.image == nil then
self.screensaver_type = "random_image"
end
end
else
self.screensaver_type = "random_image"
@ -463,13 +467,6 @@ function Screensaver:setup(event, event_message)
self.screensaver_type = "random_image"
end
end
if self.screensaver_type == "image_file" then
self.image_file = G_reader_settings:readSetting(self.prefix .. "screensaver_image")
or G_reader_settings:readSetting("screensaver_image")
if self.image_file == nil or lfs.attributes(self.image_file, "mode") ~= "file" then
self.screensaver_type = "random_image"
end
end
if self.screensaver_type == "readingprogress" then
-- This is implemented by the Statistics plugin
if Screensaver.getReaderProgress == nil then
@ -542,15 +539,22 @@ function Screensaver:show()
-- Build the main widget for the effective mode, all the sanity checks were handled in setup
local widget = nil
if self.screensaver_type == "cover" then
widget = ImageWidget:new{
image = self.image,
image_disposable = true,
if self.screensaver_type == "cover" or self.screensaver_type == "random_image" then
local widget_settings = {
width = Screen:getWidth(),
height = Screen:getHeight(),
scale_factor = G_reader_settings:isFalse("screensaver_stretch_images") and 0 or nil,
stretch_limit_percentage = G_reader_settings:readSetting("screensaver_stretch_limit_percentage"),
}
if self.image then
widget_settings.image = self.image
widget_settings.image_disposable = true
elseif self.image_file then
widget_settings.file = self.image_file
widget_settings.file_do_cache = false
widget_settings.alpha = true
end
widget = ImageWidget:new(widget_settings)
elseif self.screensaver_type == "bookstatus" then
local ReaderUI = require("apps/reader/readerui")
local ui = ReaderUI.instance
@ -564,16 +568,6 @@ function Screensaver:show()
ui = ui,
readonly = true,
}
elseif self.screensaver_type == "random_image" or self.screensaver_type == "image_file" then
widget = ImageWidget:new{
file = self.image_file,
file_do_cache = false,
alpha = true,
width = Screen:getWidth(),
height = Screen:getHeight(),
scale_factor = G_reader_settings:isFalse("screensaver_stretch_images") and 0 or nil,
stretch_limit_percentage = G_reader_settings:readSetting("screensaver_stretch_limit_percentage"),
}
elseif self.screensaver_type == "readingprogress" then
widget = Screensaver.getReaderProgress()
end
@ -698,7 +692,7 @@ function Screensaver:show()
self.screensaver_widget.modal = true
self.screensaver_widget.dithered = true
UIManager:show(self.screensaver_widget, "full")
UIManager:show(self.screensaver_widget, Device:hasKaleidoWfm() and "color" or "full")
end
-- Setup the gesture lock through an additional invisible widget, so that it works regardless of the configuration.

@ -503,14 +503,14 @@ Show translated text in TextViewer, with alternate translations
@string source_lang[opt="auto"] (`"en"`, `"fr"`, ``) or `"auto"` to auto-detect source language
@string target_lang[opt] (`"en"`, `"fr"`, ``)
--]]
function Translator:showTranslation(text, detailed_view, source_lang, target_lang, from_highlight, page, index)
function Translator:showTranslation(text, detailed_view, source_lang, target_lang, from_highlight, index)
if Device:hasClipboard() then
Device.input.setClipboardText(text)
end
local NetworkMgr = require("ui/network/manager")
if NetworkMgr:willRerunWhenOnline(function()
self:showTranslation(text, detailed_view, source_lang, target_lang, from_highlight, page, index)
self:showTranslation(text, detailed_view, source_lang, target_lang, from_highlight, index)
end) then
return
end
@ -519,11 +519,11 @@ function Translator:showTranslation(text, detailed_view, source_lang, target_lan
-- translation service query.
local Trapper = require("ui/trapper")
Trapper:wrap(function()
self:_showTranslation(text, detailed_view, source_lang, target_lang, from_highlight, page, index)
self:_showTranslation(text, detailed_view, source_lang, target_lang, from_highlight, index)
end)
end
function Translator:_showTranslation(text, detailed_view, source_lang, target_lang, from_highlight, page, index)
function Translator:_showTranslation(text, detailed_view, source_lang, target_lang, from_highlight, index)
if not target_lang then
target_lang = self:getTargetLanguage()
end
@ -632,8 +632,8 @@ function Translator:_showTranslation(text, detailed_view, source_lang, target_la
UIManager:close(textviewer)
UIManager:close(ui.highlight.highlight_dialog)
ui.highlight.highlight_dialog = nil
if page then
ui.highlight:editHighlight(page, index, false, text_main)
if index then
ui.highlight:editHighlight(index, false, text_main)
else
ui.highlight:addNote(text_main)
end
@ -645,8 +645,8 @@ function Translator:_showTranslation(text, detailed_view, source_lang, target_la
UIManager:close(textviewer)
UIManager:close(ui.highlight.highlight_dialog)
ui.highlight.highlight_dialog = nil
if page then
ui.highlight:editHighlight(page, index, false, text_all)
if index then
ui.highlight:editHighlight(index, false, text_all)
else
ui.highlight:addNote(text_all)
end

@ -616,7 +616,7 @@ function Trapper:dismissableRunInSubprocess(task, trap_widget_or_string, task_re
end
-- The go_on_func resumed us: we have not been dismissed.
-- Check if sub process has ended
-- Depending on the the size of what the child has to write,
-- Depending on the size of what the child has to write,
-- it may has ended (if data fits in the kernel pipe buffer) or
-- it may still be alive blocking on write() (if data exceeds
-- the kernel pipe buffer)

@ -62,11 +62,15 @@ function UIManager:init()
UsbDevicePlugIn = function(input_event)
-- Retrieve the argument set by Input:handleKeyBoardEv
local evdev = table.remove(Input.fake_event_args[input_event])
self:broadcastEvent(Event:new("EvdevInputInsert", evdev))
local path = "/dev/input/event" .. tostring(evdev)
self:broadcastEvent(Event:new("EvdevInputInsert", path))
end,
UsbDevicePlugOut = function(input_event)
local evdev = table.remove(Input.fake_event_args[input_event])
self:broadcastEvent(Event:new("EvdevInputRemove", evdev))
local path = "/dev/input/event" .. tostring(evdev)
self:broadcastEvent(Event:new("EvdevInputRemove", path))
end,
}
self.poweroff_action = function()
@ -134,7 +138,7 @@ For more details about refreshtype, refreshregion & refreshdither see the descri
If refreshtype is omitted, no refresh will be enqueued at this time.
@param widget a @{ui.widget.widget|widget} object
@string refreshtype `"full"`, `"flashpartial"`, `"flashui"`, `"[partial]"`, `"[ui]"`, `"partial"`, `"ui"`, `"fast"`, `"a2"` (optional)
@string refreshtype `"color"`, `"colortext"`, `"full"`, `"flashpartial"`, `"flashui"`, `"[partial]"`, `"[ui]"`, `"partial"`, `"ui"`, `"fast"`, `"a2"` (optional)
@param refreshregion a rectangle @{ui.geometry.Geom|Geom} object (optional, requires refreshtype to be set)
@int x horizontal screen offset (optional, `0` if omitted)
@int y vertical screen offset (optional, `0` if omitted)
@ -191,7 +195,7 @@ For more details about refreshtype, refreshregion & refreshdither see the descri
If refreshtype is omitted, no extra refresh will be enqueued at this time, leaving only those from the uncovered widgets.
@param widget a @{ui.widget.widget|widget} object
@string refreshtype `"full"`, `"flashpartial"`, `"flashui"`, `"[partial]"`, `"[ui]"`, `"partial"`, `"ui"`, `"fast"`, `"a2"` (optional)
@string refreshtype `"color"`, `"colortext"`, `"full"`, `"flashpartial"`, `"flashui"`, `"[partial]"`, `"[ui]"`, `"partial"`, `"ui"`, `"fast"`, `"a2"` (optional)
@param refreshregion a rectangle @{ui.geometry.Geom|Geom} object (optional, requires refreshtype to be set)
@bool refreshdither `true` if the refresh requires dithering (optional, requires refreshtype to be set)
@see setDirty
@ -460,6 +464,10 @@ It just appends stuff to the paint and/or refresh queues.
Here's a quick rundown of what each refreshtype should be used for:
* `color`: high-fidelity flashing refresh for color image content on Kaleido panels.
Maps to partial on unsupported devices, as such, better used conditionally behind a Device:hasKaleidoWfm check.
* `colortext`: REAGL refresh for color text (e.g., highlights) on Kaleido panels.
Maps to partial on unsupported devices, as such, better used conditionally behind a Device:hasKaleidoWfm check.
* `full`: high-fidelity flashing refresh (e.g., large images).
Highest quality, but highest latency.
Don't abuse if you only want a flash (in this case, prefer `flashui` or `flashpartial`).
@ -558,7 +566,7 @@ UIManager:setDirty(self.widget, "partial", Geom:new{x=10,y=10,w=100,h=50})
UIManager:setDirty(self.widget, function() return "ui", self.someelement.dimen end)
@param widget a window-level widget object, `"all"`, or `nil`
@param refreshtype `"full"`, `"flashpartial"`, `"flashui"`, `"[partial]"`, `"[ui]"`, `"partial"`, `"ui"`, `"fast"`, `"a2"` (or a lambda, see description above)
@param refreshtype `"color"`, `"colortext"`, `"full"`, `"flashpartial"`, `"flashui"`, `"[partial]"`, `"[ui]"`, `"partial"`, `"ui"`, `"fast"`, `"a2"` (or a lambda, see description above)
@param refreshregion a rectangle @{ui.geometry.Geom|Geom} object (optional, omitting it means the region will cover the full screen)
@bool refreshdither `true` if widget requires dithering (optional)
]]
@ -1050,7 +1058,7 @@ function UIManager:getElapsedTimeSinceBoot()
end
-- precedence of refresh modes:
local refresh_modes = { a2 = 1, fast = 2, ui = 3, partial = 4, ["[ui]"] = 5, ["[partial]"] = 6, flashui = 7, flashpartial = 8, full = 9 }
local refresh_modes = { a2 = 1, fast = 2, ui = 3, partial = 4, ["[ui]"] = 5, ["[partial]"] = 6, flashui = 7, flashpartial = 8, full = 9, colortext = 10, color = 11 }
-- NOTE: We might want to introduce a "force_a2" that points to fast, but has the highest priority,
-- for the few cases where we might *really* want to enforce fast (for stuff like panning or skimming?).
-- refresh methods in framebuffer implementation
@ -1064,6 +1072,8 @@ local refresh_methods = {
flashui = Screen.refreshFlashUI,
flashpartial = Screen.refreshFlashPartial,
full = Screen.refreshFull,
colortext = Screen.refreshColorText,
color = Screen.refreshColor,
}
--[[
@ -1101,7 +1111,7 @@ Widgets call this in their `paintTo()` method in order to notify
UIManager that a certain part of the screen is to be refreshed.
@string mode
refresh mode (`"full"`, `"flashpartial"`, `"flashui"`, `"[partial]"`, `"[ui]"`, `"partial"`, `"ui"`, `"fast"`, `"a2"`)
refresh mode (`"color"`, `"colortext"`, `"full"`, `"flashpartial"`, `"flashui"`, `"[partial]"`, `"[ui]"`, `"partial"`, `"ui"`, `"fast"`, `"a2"`)
@param region
A rectangle @{ui.geometry.Geom|Geom} object that specifies the region to be updated.
Optional, update will affect whole screen if not specified.

@ -96,7 +96,7 @@ function FrameContainer:paintTo(bb, x, y)
if not self.dimen then
self.dimen = Geom:new{
x = x, y = y,
w = my_size.w, h = my_size.h
w = my_size.w, h = my_size.h,
}
else
self.dimen.x = x
@ -110,11 +110,16 @@ function FrameContainer:paintTo(bb, x, y)
shift_x = container_width - my_size.w
end
--- @todo get rid of margin here? 13.03 2013 (houqp)
if self.background then
bb:paintRoundedRect(x, y,
container_width, container_height,
self.background, self.radius)
if not self.radius or not self.bordersize then
bb:paintRoundedRect(x, y,
container_width, container_height,
self.background, self.radius)
else
bb:paintRoundedRect(x, y,
container_width, container_height,
self.background, self.radius + self.bordersize)
end
end
if self.stripe_width and self.stripe_color and not self.stripe_over then
-- (No support for radius when hatched/stripe)
@ -130,10 +135,11 @@ function FrameContainer:paintTo(bb, x, y)
self.inner_bordersize, self.color, self.radius)
end
if self.bordersize > 0 then
local anti_alias = G_reader_settings:nilOrTrue("anti_alias_ui")
bb:paintBorder(x + self.margin, y + self.margin,
container_width - self.margin * 2,
container_height - self.margin * 2,
self.bordersize, self.color, self.radius)
self.bordersize, self.color, self.radius, anti_alias)
end
if self[1] then
self[1]:paintTo(bb,

@ -74,7 +74,7 @@ function InputContainer:paintTo(bb, x, y)
local content_size = self[1]:getSize()
self.dimen = Geom:new{
x = x, y = y,
w = content_size.w, h = content_size.h
w = content_size.w, h = content_size.h,
}
else
self.dimen.x = x

@ -65,11 +65,6 @@ local DictQuickLookup = InputContainer:extend{
rotated_update_wiki_languages_on_close = nil,
}
local highlight_strings = {
highlight =_("Highlight"),
unhighlight = _("Unhighlight"),
}
function DictQuickLookup.getWikiSaveEpubDefaultDir()
local dir = G_reader_settings:readSetting("home_dir") or filemanagerutil.getDefaultDir()
if dir:sub(-1) ~= "/" then
@ -110,6 +105,7 @@ function DictQuickLookup:init()
ReadPrevResult = { { Input.group.PgBack } },
ReadNextResult = { { Input.group.PgFwd } },
Close = { { Input.group.Back } },
ShowResultsMenu = { { "Menu" } },
}
end
if Device:isTouchDevice() then
@ -438,19 +434,13 @@ function DictQuickLookup:init()
},
{
id = "highlight",
text = self:getHighlightText(),
text = _("Highlight"),
enabled = not self:isDocless() and self.highlight ~= nil,
callback = function()
if self:getHighlightText() == highlight_strings.highlight then
self.ui:handleEvent(Event:new("Highlight"))
else
self.ui:handleEvent(Event:new("Unhighlight"))
end
self.save_highlight = not self.save_highlight
-- Just update, repaint and refresh *this* button
local this = self.button_table:getButtonById("highlight")
if not this then return end
this:enableDisable(self.highlight ~= nil)
this:setText(self:getHighlightText(), this.width)
this:setText(self.save_highlight and _("Unhighlight") or _("Highlight"), this.width)
this:refresh()
end,
},
@ -537,8 +527,8 @@ function DictQuickLookup:init()
})
end
end
if self.tweak_buttons_func then
self:tweak_buttons_func(buttons)
if self.ui then
self.ui:handleEvent(Event:new("DictButtonsReady", self, buttons))
end
-- Bottom buttons get a bit less padding so their line separators
-- reach out from the content to the borders a bit more
@ -729,6 +719,14 @@ function DictQuickLookup:init()
self.movable,
}
-- NT: add dict_title.left_button and lookup_edit_button to FocusManager.
-- It is better to add these two buttons into self.movable, but it is not a FocusManager.
-- Only self.button_table is a FocusManager, so workaground is inserting these two buttons into self.button_table.layout.
if Device:hasDPad() then
table.insert(self.button_table.layout, 1, { self.dict_title.left_button });
table.insert(self.button_table.layout, 2, { lookup_edit_button });
end
-- We're a new window
table.insert(DictQuickLookup.window_list, self)
end
@ -953,22 +951,6 @@ function DictQuickLookup:onShow()
return true
end
function DictQuickLookup:getHighlightedItem()
if self:isDocless() then return end
return self.ui.highlight:getHighlightBookmarkItem()
end
function DictQuickLookup:getHighlightText()
local item = self:getHighlightedItem()
if not item then
return highlight_strings.highlight, false
elseif self.ui.bookmark:isBookmarkAdded(item) then
return highlight_strings.unhighlight, false
else
return highlight_strings.highlight, true
end
end
function DictQuickLookup:isPrevDictAvaiable()
return self.dict_index > 1
end
@ -1150,13 +1132,19 @@ function DictQuickLookup:onClose(no_clear)
self.ui:handleEvent(Event:new("UpdateWikiLanguages", self.wiki_languages))
end
end
if self.highlight and not no_clear then
-- delay unhighlight of selection, so we can see where we stopped when
-- back from our journey into dictionary or wikipedia
local clear_id = self.highlight:getClearId()
UIManager:scheduleIn(0.5, function()
self.highlight:clear(clear_id)
end)
if self.save_highlight then
self.highlight:saveHighlight()
self.highlight:clear()
else
if self.highlight and not no_clear then
-- delay unhighlight of selection, so we can see where we stopped when
-- back from our journey into dictionary or wikipedia
local clear_id = self.highlight:getClearId()
UIManager:scheduleIn(0.5, function()
self.highlight:clear(clear_id)
end)
end
end
return true
end
@ -1239,6 +1227,19 @@ function DictQuickLookup:onForwardingPan(arg, ges)
end
function DictQuickLookup:onForwardingPanRelease(arg, ges)
-- Allow scrolling with the mousewheel
if ges.from_mousewheel and ges.relative and ges.relative.y then
if ges.relative.y < 0 then
if not self.definition_widget[1]:onScrollDown() then
self:onReadNextResult()
end
elseif ges.relative.y > 0 then
if not self.definition_widget[1]:onScrollUp() then
self:onReadPrevResult()
end
end
return true
end
-- We can forward onMovablePanRelease() does enough checks
return self.movable:onMovablePanRelease(arg, ges)
end
@ -1328,6 +1329,10 @@ function DictQuickLookup:lookupWikipedia(get_fullpage, word, is_sane, lang)
self.ui:handleEvent(Event:new("LookupWikipedia", word, is_sane, self.word_boxes, get_fullpage, lang))
end
function DictQuickLookup:onShowResultsMenu()
return self:showResultsMenu()
end
function DictQuickLookup:showResultsMenu()
-- Show one row: "| word | dict |" for each result
local width = math.floor(self.width * 0.75)

@ -6,6 +6,7 @@ local DocumentRegistry = require("document/documentregistry")
local FileManagerShortcuts = require("apps/filemanager/filemanagershortcuts")
local filemanagerutil = require("apps/filemanager/filemanagerutil")
local Menu = require("ui/widget/menu")
local ReadCollection = require("readcollection")
local UIManager = require("ui/uimanager")
local ffi = require("ffi")
local ffiUtil = require("ffi/util")
@ -172,7 +173,9 @@ local FileChooser = Menu:extend{
local doc_settings = DocSettings:open(item.path)
percent_finished = doc_settings:readSetting("percent_finished")
end
item.percent_finished = percent_finished or 0
-- smooth 2 decimal points (0.00) instead of 16 decimal points
item.percent_finished = util.round_decimal(percent_finished or 0, 2)
end,
mandatory_func = function(item)
return item.opened and string.format("%d %%", 100 * item.percent_finished) or ""
@ -200,29 +203,31 @@ local FileChooser = Menu:extend{
local doc_settings = DocSettings:open(item.path)
percent_finished = doc_settings:readSetting("percent_finished")
end
item.percent_finished = percent_finished or 0
-- smooth 2 decimal points (0.00) instead of 16 decimal points
item.percent_finished = util.round_decimal(percent_finished or 0, 2)
end,
mandatory_func = function(item)
return item.opened and string.format("%d %%", 100 * item.percent_finished) or ""
end,
},
percent_natural = {
-- sort 90% > 50% > 0% > unopened > 100% or finished
text = _("percent - unopened - finished last"),
-- sort 90% > 50% > 0% or on hold > unopened > 100% or finished
text = _("percent unopened finished last"),
menu_order = 90,
can_collate_mixed = false,
init_sort_func = function(cache)
local natsort
natsort, cache = sort.natsort_cmp(cache)
local sortfunc = function(a, b)
if a.percent_finished == b.percent_finished then
if a.sort_percent == b.sort_percent then
return natsort(a.text, b.text)
elseif a.percent_finished == 1 then
elseif a.sort_percent == 1 then
return false
elseif b.percent_finished == 1 then
elseif b.sort_percent == 1 then
return true
else
return a.percent_finished > b.percent_finished
return a.sort_percent > b.sort_percent
end
end
@ -230,21 +235,24 @@ local FileChooser = Menu:extend{
end,
item_func = function(item)
local percent_finished
local sort_percent
item.opened = DocSettings:hasSidecarFile(item.path)
if item.opened then
local doc_settings = DocSettings:open(item.path)
local summary = doc_settings:readSetting("summary")
-- books marked as "finished" should be considered the same as 100%
-- books marked as "finished" or "on hold" should be considered the same as 100% and 0% respectively
if summary and summary.status == "complete" then
item.percent_finished = 1.0
return
sort_percent = 1.0
elseif summary and summary.status == "abandoned" then
sort_percent = 0
end
percent_finished = doc_settings:readSetting("percent_finished")
end
-- smooth 2 decimal points (0.00) instead of 16 decimal numbers
item.percent_finished = math.floor((percent_finished or -1) * 100) / 100
-- smooth 2 decimal points (0.00) instead of 16 decimal points
item.sort_percent = sort_percent or util.round_decimal(percent_finished or -1, 2)
item.percent_finished = percent_finished or 0
end,
mandatory_func = function(item)
return item.opened and string.format("%d %%", 100 * item.percent_finished) or ""
@ -279,8 +287,8 @@ function FileChooser:init()
if lfs.attributes(self.path, "mode") ~= "directory" then
self.path = G_reader_settings:readSetting("home_dir") or filemanagerutil.getDefaultDir()
end
self.item_table = self:genItemTableFromPath(self.path)
Menu.init(self) -- call parent's init()
self:refreshPath()
end
function FileChooser:getList(path, collate)
@ -468,6 +476,9 @@ function FileChooser:getMenuItemMandatory(item, collate)
else
text = util.getFriendlySize(item.attr.size or 0)
end
if ReadCollection:isFileInCollections(item.path) then
text = "" .. text
end
else -- folder, count number of folders and files inside it
local sub_dirs, dir_files = self:getList(item.path)
text = T("%1 \u{F016}", #dir_files)
@ -481,18 +492,17 @@ function FileChooser:getMenuItemMandatory(item, collate)
return text
end
function FileChooser:updateItems(select_number)
Menu.updateItems(self, select_number) -- call parent's updateItems()
function FileChooser:updateItems(select_number, no_recalculate_dimen)
Menu.updateItems(self, select_number, no_recalculate_dimen) -- call parent's updateItems()
self:mergeTitleBarIntoLayout()
self.path_items[self.path] = (self.page - 1) * self.perpage + (select_number or 1)
end
function FileChooser:refreshPath()
local itemmatch = nil
local _, folder_name = util.splitFilePathName(self.path)
Screen:setWindowTitle(folder_name)
local itemmatch
if self.focused_path then
itemmatch = {path = self.focused_path}
-- We use focused_path only once, but remember it
@ -500,8 +510,8 @@ function FileChooser:refreshPath()
self.prev_focused_path = self.focused_path
self.focused_path = nil
end
self:switchItemTable(nil, self:genItemTableFromPath(self.path), self.path_items[self.path], itemmatch)
local subtitle = BD.directory(filemanagerutil.abbreviate(self.path))
self:switchItemTable(nil, self:genItemTableFromPath(self.path), self.path_items[self.path], itemmatch, subtitle)
end
function FileChooser:changeToPath(path, focused_path)
@ -639,7 +649,7 @@ function FileChooser:selectAllFilesInFolder(do_select)
end
end
end
self:updateItems()
self:updateItems(1, true)
end
return FileChooser

@ -53,11 +53,12 @@ local function populateEventMappings()
local FEW_KEYS_END_INDEX = #event_keys -- Few keys device: only setup up, down, right and press
table.insert(event_keys, { "FocusLeft", { { "Left" }, event = "FocusMove", args = {-1, 0} } })
local NORMAL_KEYS_END_INDEX = #event_keys
-- Advanced Feature: following event handlers can be enabled via settings.reader.lua
-- Key combinations (Sym+AA, Alt+Up, Tab, Shift+Tab and so on) are not used but shown as examples here
table.insert(event_keys, { "Hold", { { "Sym", "AA" }, event = "Hold" } })
-- Advanced features: more event handlers can be enabled via settings.reader.lua in a similar manner
table.insert(event_keys, { "HoldContext", { { "ContextMenu" }, event = "Hold" } })
table.insert(event_keys, { "HoldShift", { { "Shift", "Press" }, event = "Hold" } })
table.insert(event_keys, { "HoldScreenKB", { { "ScreenKB", "Press" }, event = "Hold" } })
table.insert(event_keys, { "HoldSymAA", { { "Sym", "AA" }, event = "Hold" } })
-- half rows/columns move, it is helpful for slow device like Kindle DX to move quickly
table.insert(event_keys, { "HalfFocusUp", { { "Alt", "Up" }, event = "FocusHalfMove", args = {"up"} } })
table.insert(event_keys, { "HalfFocusRight", { { "Alt", "Right" }, event = "FocusHalfMove", args = {"right"} } })
@ -66,6 +67,7 @@ local function populateEventMappings()
-- for PC navigation behavior support
table.insert(event_keys, { "FocusNext", { { "Tab" }, event = "FocusNext" } })
table.insert(event_keys, { "FocusPrevious", { { "Shift", "Tab" }, event = "FocusPrevious" } })
local NORMAL_KEYS_END_INDEX = #event_keys
for i = 1, FEW_KEYS_END_INDEX do
local key_name = event_keys[i][1]

@ -369,13 +369,14 @@ function ImageViewer:update()
self.main_frame.radius = not self.fullscreen and 8 or nil
-- NOTE: We use UI instead of partial, because we do NOT want to end up using a REAGL waveform...
local wfm_mode = Device:hasKaleidoWfm() and "color" or "ui"
-- NOTE: Disabling dithering here makes for a perfect test-case of how well it works:
-- page turns will show color quantization artefacts (i.e., banding) like crazy,
-- while a long touch will trigger a dithered, flashing full-refresh that'll make everything shiny :).
self.dithered = true
UIManager:setDirty(self, function()
local update_region = self.main_frame.dimen:combine(orig_dimen)
return "ui", update_region, true
return wfm_mode, update_region, true
end)
end

@ -113,7 +113,7 @@ local ImageWidget = Widget:extend{
_max_off_center_y_ratio = 0,
-- So we can reset self.scale_factor to its initial value in free(), in
-- case this same object is free'd but re-used and and re-render'ed
-- case this same object is free'd but re-used and re-render'ed
_initial_scale_factor = nil,
_bb = nil,

@ -532,6 +532,10 @@ function InputDialog:setInputText(text, edited_state, cursor_at_start_or_end)
end
end
function InputDialog:addTextToInput(text)
return self._input_widget:addChars(text)
end
function InputDialog:isTextEditable()
return self._input_widget:isTextEditable()
end

@ -213,7 +213,7 @@ local function initTouchEvents()
text = _("Copy line"),
callback = function()
UIManager:close(clipboard_dialog)
local txt = table.concat(self.charlist, "", self:getStringPos({"\n", "\r"}, {"\n", "\r"}))
local txt = table.concat(self.charlist, "", self:getStringPos())
Device.input.setClipboardText(txt)
UIManager:show(Notification:new{
text = _("Line copied to clipboard."),
@ -224,7 +224,7 @@ local function initTouchEvents()
text = _("Copy word"),
callback = function()
UIManager:close(clipboard_dialog)
local txt = table.concat(self.charlist, "", self:getStringPos({"\n", "\r", " "}, {"\n", "\r", " "}))
local txt = table.concat(self.charlist, "", self:getStringPos(true))
Device.input.setClipboardText(txt)
UIManager:show(Notification:new{
text = _("Word copied to clipboard."),
@ -763,39 +763,31 @@ function InputText:getLineCharPos(line_num)
return char_pos
end
-- Get start and end positions of the substring
-- delimited with the delimiters and containing char_pos.
-- If char_pos not set, current charpos assumed.
function InputText:getStringPos(left_delimiter, right_delimiter, char_pos)
char_pos = char_pos and char_pos or self.charpos
local start_pos, end_pos = 1, #self.charlist
local done = false
if char_pos > 1 then
for i = char_pos, 2, -1 do
for j = 1, #left_delimiter do
if self.charlist[i-1] == left_delimiter[j] then
start_pos = i
done = true
break
end
-- Get start and end positions of a line (or a word) under the cursor.
function InputText:getStringPos(is_word, left_to_cursor)
local delimiter = is_word and "[\n\r%s.,;:!?–—―]" or "[\n\r]"
local start_pos, end_pos
if self.charpos > 1 then
for i = self.charpos - 1, 1, -1 do
if self.charlist[i]:find(delimiter) then
start_pos = i + 1
break
end
if done then break end
end
end
done = false
if char_pos < #self.charlist then
for i = char_pos, #self.charlist do
for j = 1, #right_delimiter do
if self.charlist[i] == right_delimiter[j] then
if left_to_cursor then
end_pos = self.charpos - 1
else
if self.charpos <= #self.charlist then
for i = self.charpos, #self.charlist do
if self.charlist[i]:find(delimiter) then
end_pos = i - 1
done = true
break
end
end
if done then break end
end
end
return start_pos, end_pos
return start_pos or 1, end_pos or #self.charlist
end
--- Return the character at the given offset. If is_absolute is truthy then the
@ -861,6 +853,27 @@ function InputText:delNextChar()
self:initTextBox(table.concat(self.charlist))
end
function InputText:delWord(left_to_cursor)
if self.readonly or not self:isTextEditable(true) then
return
end
local start_pos, end_pos = self:getStringPos(true, left_to_cursor)
for i = end_pos, start_pos, -1 do
table.remove(self.charlist, i)
end
if #self.charlist > 0 then
local prev_pos = start_pos > 1 and start_pos - 1 or 1
if not left_to_cursor and self.charlist[prev_pos]:find("[ \t]") then -- remove redundant space
table.remove(self.charlist, prev_pos)
self.charpos = prev_pos
else
self.charpos = start_pos
end
end
self.is_text_edited = true
self:initTextBox(table.concat(self.charlist))
end
function InputText:delToStartOfLine()
if self.readonly or not self:isTextEditable(true) then
return
@ -906,14 +919,14 @@ function InputText:rightChar()
end
function InputText:goToStartOfLine()
local new_pos = select(1, self:getStringPos({"\n", "\r"}, {"\n", "\r"}))
local new_pos = self:getStringPos()
self.text_widget:moveCursorToCharPos(new_pos)
self:resyncPos()
end
function InputText:goToEndOfLine()
local new_pos = select(2, self:getStringPos({"\n", "\r"}, {"\n", "\r"})) + 1
self.text_widget:moveCursorToCharPos(new_pos)
local _, new_pos = self:getStringPos()
self.text_widget:moveCursorToCharPos(new_pos + 1)
self:resyncPos()
end

@ -13,7 +13,6 @@ local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local HorizontalGroup = require("ui/widget/horizontalgroup")
local HorizontalSpan = require("ui/widget/horizontalspan")
local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer")
local LeftContainer = require("ui/widget/container/leftcontainer")
local Math = require("optmath")
@ -29,7 +28,6 @@ local Utf8Proc = require("ffi/utf8proc")
local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local filemanagerutil = require("apps/filemanager/filemanagerutil")
local logger = require("logger")
local util = require("util")
local _ = require("gettext")
@ -89,18 +87,8 @@ end
Widget that displays an item for menu
--]]
local MenuItem = InputContainer:extend{
text = nil,
bidi_wrap_func = nil,
show_parent = nil,
detail = nil,
font = "cfont",
font_size = 24,
font = "smallinfofont",
infont = "infont",
infont_size = 18,
dimen = nil,
shortcut = nil,
shortcut_style = "square",
_underline_container = nil,
linesize = Size.line.medium,
single_line = false,
multilines_show_more_text = false,
@ -112,19 +100,19 @@ local MenuItem = InputContainer:extend{
function MenuItem:init()
self.content_width = self.dimen.w - 2 * Size.padding.fullscreen
local icon_width = math.floor(self.dimen.h * 4/5)
local shortcut_icon_dimen = Geom:new{
x = 0,
y = 0,
w = icon_width,
h = icon_width,
}
local shortcut_icon_dimen
if self.shortcut then
local icon_width = math.floor(self.dimen.h * 4/5)
shortcut_icon_dimen = Geom:new{
x = 0,
y = 0,
w = icon_width,
h = icon_width,
}
self.content_width = self.content_width - shortcut_icon_dimen.w - Size.span.horizontal_default
end
self.detail = self.text
-- we need this table per-instance, so we declare it here
self.ges_events = {
TapSelect = {
@ -167,9 +155,9 @@ function MenuItem:init()
end
-- State button and indentation for tree expand/collapse (for TOC)
local state_button = self.state or HorizontalSpan:new{}
local state_indent = self.table.indent or 0
local state_width = state_indent + self.state_w
local state_button = self.entry.state or HorizontalSpan:new{}
local state_indent = self.entry.indent or 0
local state_width = state_indent + (self.state_w or 0)
local state_container = LeftContainer:new{
dimen = Geom:new{w = math.floor(self.content_width / 2), h = self.dimen.h},
HorizontalGroup:new{
@ -184,6 +172,12 @@ function MenuItem:init()
self.face = Font:getFace(self.font, self.font_size)
-- Font for "mandatory" on the right
self.info_face = Font:getFace(self.infont, self.infont_size)
-- Font for post_text if any: for now, this is only used with TOC, showing
-- the chapter length: if feels best to use the face of the main text, but
-- with the size of the mandatory font (which shows some number too).
if self.post_text then
self.post_text_face = Font:getFace(self.font, self.infont_size)
end
-- "mandatory" is the text on the right: file size, page number...
-- Padding before mandatory
@ -219,10 +213,25 @@ function MenuItem:init()
text = self.bidi_wrap_func(text)
end
-- Note: support for post_text is currently implemented only when single_line=true
local post_text_widget
local post_text_left_padding = Size.padding.large
local post_text_right_padding = self.with_dots and 0 or Size.padding.large
local dots_widget
local dots_left_padding = Size.padding.small
local dots_right_padding = Size.padding.small
if self.single_line then -- items only in single line
if self.single_line then
-- Items only in single line
if self.post_text then
post_text_widget = TextWidget:new{
text = self.post_text,
face = self.post_text_face,
bold = self.bold,
fgcolor = self.dim and Blitbuffer.COLOR_DARK_GRAY or nil,
}
available_width = available_width - post_text_widget:getWidth() - post_text_left_padding - post_text_right_padding
end
-- No font size change: text will be truncated if it overflows
item_name = TextWidget:new{
text = text,
@ -271,6 +280,9 @@ function MenuItem:init()
if dots_widget then
dots_widget.forced_height = self.dimen.h
end
if post_text_widget then
post_text_widget.forced_height = self.dimen.h
end
-- And adjust their baselines for proper centering and alignment
-- (We made sure the font sizes wouldn't exceed self.dimen.h, so we
-- get only non-negative pad_top here, and we're moving them down.)
@ -289,6 +301,9 @@ function MenuItem:init()
if dots_widget then
dots_widget.forced_baseline = mdtr_baseline
end
if post_text_widget then
post_text_widget.forced_baseline = mdtr_baseline
end
end
elseif self.multilines_show_more_text then
@ -352,6 +367,7 @@ function MenuItem:init()
end
end
end
else
-- Multi-lines, with fixed user provided font size
item_name = TextBoxWidget:new {
@ -374,6 +390,8 @@ function MenuItem:init()
width = state_width,
},
item_name,
post_text_widget and HorizontalSpan:new{ width = post_text_left_padding },
post_text_widget,
}
}
@ -455,7 +473,6 @@ function MenuItem:getDotsText(face)
}
end
return _dots_cached_info.text, _dots_cached_info.min_width
end
function MenuItem:onFocus(initial_focus)
@ -480,11 +497,6 @@ function MenuItem:onUnfocus()
return true
end
function MenuItem:onShowItemDetail()
UIManager:show(InfoMessage:new{ text = self.detail, })
return true
end
function MenuItem:getGesPosition(ges)
local dimen = self[1].dimen
return {
@ -499,7 +511,7 @@ function MenuItem:onTapSelect(arg, ges)
local pos = self:getGesPosition(ges)
if G_reader_settings:isFalse("flash_ui") then
self.menu:onMenuSelect(self.table, pos)
self.menu:onMenuSelect(self.entry, pos)
else
-- c.f., ui/widget/iconbutton for the canonical documentation about the flash_ui code flow
@ -520,7 +532,7 @@ function MenuItem:onTapSelect(arg, ges)
-- Callback
--
self.menu:onMenuSelect(self.table, pos)
self.menu:onMenuSelect(self.entry, pos)
UIManager:forceRePaint()
end
@ -532,7 +544,7 @@ function MenuItem:onHoldSelect(arg, ges)
local pos = self:getGesPosition(ges)
if G_reader_settings:isFalse("flash_ui") then
self.menu:onMenuHold(self.table, pos)
self.menu:onMenuHold(self.entry, pos)
else
-- c.f., ui/widget/iconbutton for the canonical documentation about the flash_ui code flow
@ -553,7 +565,7 @@ function MenuItem:onHoldSelect(arg, ges)
-- Callback
--
self.menu:onMenuHold(self.table, pos)
self.menu:onMenuHold(self.entry, pos)
UIManager:forceRePaint()
end
@ -614,39 +626,45 @@ local Menu = FocusManager:extend{
line_color = Blitbuffer.COLOR_DARK_GRAY,
}
function Menu:_recalculateDimen()
self.perpage = self.items_per_page or G_reader_settings:readSetting("items_per_page") or self.items_per_page_default
self.span_width = 0
local height_dim
local bottom_height = 0
local top_height = 0
if self.page_return_arrow and self.page_info_text then
bottom_height = math.max(self.page_return_arrow:getSize().h, self.page_info_text:getSize().h)
+ 2 * Size.padding.button
function Menu:_recalculateDimen(no_recalculate_dimen)
local perpage = self.items_per_page or G_reader_settings:readSetting("items_per_page") or self.items_per_page_default
if self.perpage ~= perpage then
self.perpage = perpage
no_recalculate_dimen = false
end
if no_recalculate_dimen then return end
local top_height = 0
if self.title_bar and not self.no_title then
top_height = self.title_bar:getHeight()
if not self.title_bar_fm_style then
top_height = top_height + self.header_padding
end
end
height_dim = self.inner_dimen.h - bottom_height - top_height
local item_height = math.floor(height_dim / self.perpage)
self.span_width = math.floor((height_dim - (self.perpage * item_height)) / 2 - 1)
local bottom_height = 0
if self.page_return_arrow and self.page_info_text then
bottom_height = math.max(self.page_return_arrow:getSize().h, self.page_info_text:getSize().h)
+ 2 * Size.padding.button
end
self.available_height = self.inner_dimen.h - top_height - bottom_height
self.item_dimen = Geom:new{
x = 0, y = 0,
w = self.inner_dimen.w,
h = item_height,
h = math.floor(self.available_height / perpage),
}
self.page_num = math.ceil(#self.item_table / self.perpage)
-- fix current page if out of range
if self.page_num > 0 and self.page > self.page_num then self.page = self.page_num end
self.page_num = self:getPageNumber(#self.item_table)
if self.page > self.page_num then
self.page = self.page_num
end
end
function Menu:init()
self.show_parent = self.show_parent or self
self.item_table = self.item_table or {}
self.item_table_stack = {}
self.page = 1
self.screen_w = Screen:getWidth()
self.screen_h = Screen:getHeight()
@ -661,20 +679,14 @@ function Menu:init()
h = self.dimen.h - 2 * self.border_size,
}
self.page = 1
self.paths = {} -- per instance table to trace navigation path
-----------------------------------
-- start to set up widget layout --
-----------------------------------
if self.show_path or not self.no_title then
if self.subtitle == nil then
if self.show_path then
self.subtitle = BD.directory(filemanagerutil.abbreviate(self.path))
elseif self.title_bar_fm_style then
self.subtitle = ""
end
if self.subtitle == nil and (self.show_path or self.title_bar_fm_style) then
self.subtitle = ""
end
self.title_bar = TitleBar:new{
width = self.dimen.w,
@ -771,7 +783,6 @@ function Menu:init()
if self.goto_letter then
title_goto = _("Enter letter or page number")
type_goto = "string"
hint_func = function()
-- @translators First group is the standard range for alphabetic searches, second group is a page number range
return T(_("(a - z) or (1 - %1)"), self.page_num)
@ -795,7 +806,7 @@ function Menu:init()
local filename = Utf8Proc.lowercase(util.fixUtf8(FFIUtil.basename(v.path), "?"))
local i, _ = filename:find(search_string)
if i == 1 and not v.is_go_up then
self:onGotoPage(math.ceil(k / self.perpage))
self:onGotoPage(self:getPageNumber(k))
break
end
end
@ -931,6 +942,12 @@ function Menu:init()
}
}
end
self.ges_events.Pan = { -- (for mousewheel scrolling support)
GestureRange:new{
ges = "pan",
range = self.dimen,
}
}
self.ges_events.Close = self.on_close_ges
if not Device:hasKeyboard() then
@ -949,50 +966,23 @@ function Menu:init()
end
if Device:hasDPad() then
-- we won't catch presses to "Right", leave that to MenuItem.
self.key_events.FocusRight = nil
if Device:hasFewKeys() then
-- we won't catch presses to "Right", leave that to MenuItem.
self.key_events.FocusRight = nil
-- add long press on "Right" key
self.key_events.Right = { { "Right" } }
end
-- shortcut icon is not needed for touch device
if self.is_enable_shortcut then
self.key_events.SelectByShortCut = { { self.item_shortcuts } }
end
self.key_events.Right = { { "Right" } }
end
if #self.item_table > 0 then
-- if the table is not yet initialized, this call
-- must be done manually:
self.page = math.ceil((self.item_table.current or 1) / self.perpage)
if self.item_table.current then
self.page = self:getPageNumber(self.item_table.current)
end
if self.path_items then
self:refreshPath()
else
self:updateItems()
end
end
function Menu:onShowingReader()
-- Clear the dither flag to prevent it from infecting the queue and re-inserting a full-screen refresh...
self.dithered = nil
end
Menu.onSetupShowReader = Menu.onShowingReader
function Menu:onCloseWidget()
--- @fixme
-- we cannot refresh regionally using the dimen field
-- because some menus without menu title use VerticalGroup to include
-- a text widget which is not calculated into the dimen.
-- For example, it's a dirty hack to use two menus (one being this menu and
-- the other touch menu) in the filemanager in order to capture tap gesture to popup
-- the filemanager menu.
-- NOTE: For the same reason, don't make it flash,
-- because that'll trigger when we close the FM and open a book...
-- Don't do anything if we're in the process of tearing down FM or RD, or if we don't actually have a live instance of 'em...
local FileManager = require("apps/filemanager/filemanager")
local ReaderUI = require("apps/reader/readerui")
if (FileManager.instance and not FileManager.instance.tearing_down)
or (ReaderUI.instance and not ReaderUI.instance.tearing_down) then
UIManager:setDirty(nil, "ui")
if not self.path_items then -- not FileChooser
self:updateItems(1, true)
end
end
@ -1032,7 +1022,7 @@ function Menu:updatePageInfo(select_number)
end
end
function Menu:updateItems(select_number)
function Menu:updateItems(select_number, no_recalculate_dimen)
local old_dimen = self.dimen and self.dimen:copy()
-- self.layout must be updated for focusmanager
self.layout = {}
@ -1040,8 +1030,7 @@ function Menu:updateItems(select_number)
self.page_info:resetLayout()
self.return_button:resetLayout()
self.content_group:resetLayout()
self:_recalculateDimen()
self:_recalculateDimen(no_recalculate_dimen)
-- default to select the first item
if not select_number then
select_number = 1
@ -1055,61 +1044,52 @@ function Menu:updateItems(select_number)
multilines_show_more_text = G_reader_settings:isTrue("items_multilines_show_more_text")
end
for c = 1, math.min(self.perpage, #self.item_table) do
-- calculate index in item_table
local i = (self.page - 1) * self.perpage + c
if i <= #self.item_table then
local item_shortcut = nil
local shortcut_style = "square"
if self.is_enable_shortcut then
-- give different shortcut_style to keys in different
-- lines of keyboard
if c >= 11 and c <= 20 then
--shortcut_style = "rounded_corner"
shortcut_style = "grey_square"
end
item_shortcut = self.item_shortcuts[c]
end
local item_tmp = MenuItem:new{
show_parent = self.show_parent,
state = self.item_table[i].state,
state_w = self.state_w or 0,
text = Menu.getMenuText(self.item_table[i]),
bidi_wrap_func = self.item_table[i].bidi_wrap_func,
mandatory = self.item_table[i].mandatory,
mandatory_func = self.item_table[i].mandatory_func,
mandatory_dim = self.item_table[i].mandatory_dim or self.item_table[i].dim,
bold = self.item_table.current == i or self.item_table[i].bold == true,
dim = self.item_table[i].dim,
font = "smallinfofont",
font_size = self.font_size,
infont = "infont",
infont_size = infont_size,
dimen = self.item_dimen:copy(),
shortcut = item_shortcut,
shortcut_style = shortcut_style,
table = self.item_table[i],
menu = self,
linesize = self.linesize,
single_line = self.single_line,
multilines_show_more_text = multilines_show_more_text,
truncate_left = self.truncate_left,
align_baselines = self.align_baselines,
with_dots = self.with_dots,
line_color = self.line_color,
items_padding = self.items_padding,
handle_hold_on_hold_release = self.handle_hold_on_hold_release,
}
table.insert(self.item_group, item_tmp)
-- this is for focus manager
table.insert(self.layout, {item_tmp})
end -- if i <= self.items
end -- for c=1, self.perpage
local idx_offset = (self.page - 1) * self.perpage
for idx = 1, self.perpage do
local index = idx_offset + idx
local item = self.item_table[index]
if item == nil then break end
item.idx = index -- index is valid only for items that have been displayed
local item_shortcut, shortcut_style
if self.is_enable_shortcut then
item_shortcut = self.item_shortcuts[idx]
-- give different shortcut_style to keys in different lines of keyboard
shortcut_style = (idx < 11 or idx > 20) and "square" or "grey_square"
end
local item_tmp = MenuItem:new{
show_parent = self.show_parent,
state_w = self.state_w,
text = Menu.getMenuText(item),
bidi_wrap_func = item.bidi_wrap_func,
post_text = item.post_text,
mandatory = item.mandatory,
mandatory_func = item.mandatory_func,
mandatory_dim = item.mandatory_dim or item.dim,
bold = self.item_table.current == index or item.bold == true,
dim = item.dim,
font_size = self.font_size,
infont_size = infont_size,
dimen = self.item_dimen:copy(),
shortcut = item_shortcut,
shortcut_style = shortcut_style,
entry = item,
menu = self,
linesize = self.linesize,
single_line = self.single_line,
multilines_show_more_text = multilines_show_more_text,
truncate_left = self.truncate_left,
align_baselines = self.align_baselines,
with_dots = self.with_dots,
line_color = self.line_color,
items_padding = self.items_padding,
handle_hold_on_hold_release = self.handle_hold_on_hold_release,
}
table.insert(self.item_group, item_tmp)
-- this is for focus manager
table.insert(self.layout, {item_tmp})
end
self:updatePageInfo(select_number)
if self.show_path then
self.title_bar:setSubTitle(BD.directory(filemanagerutil.abbreviate(self.path)))
end
self:mergeTitleBarIntoLayout()
UIManager:setDirty(self.show_parent, function()
@ -1139,7 +1119,6 @@ function Menu:mergeTitleBarIntoLayout()
self:moveFocusTo(1, menu_item_layout_start_row) -- move focus to first menu item if any, keep original behavior
end
--[[
the itemnumber paramter determines menu page number after switching item table
1. itemnumber >= 0
@ -1155,42 +1134,49 @@ end
which item.key = value
--]]
function Menu:switchItemTable(new_title, new_item_table, itemnumber, itemmatch, new_subtitle)
local no_recalculate_dimen = true
if new_item_table then
self.item_table = new_item_table
no_recalculate_dimen = false
end
if self.title_bar then
if new_title then
self.title_bar:setTitle(new_title, true)
if self.title_multilines then
no_recalculate_dimen = false
end
end
if new_subtitle then
if new_subtitle then -- always single line
self.title_bar:setSubTitle(new_subtitle, true)
end
end
if itemnumber == nil then
self.page = 1
elseif itemnumber >= 0 then
self.page = math.ceil(itemnumber / self.perpage)
end
if type(itemmatch) == "table" then
local key, value = next(itemmatch)
for num, item in ipairs(new_item_table) do
for num, item in ipairs(self.item_table) do
if item[key] == value then
self.page = math.floor((num-1) / self.perpage) + 1
itemnumber = num
break
end
end
end
-- make sure current page is in right page range
local max_pages = math.ceil(#new_item_table / self.perpage)
if self.page > max_pages then
self.page = max_pages
end
if self.page <= 0 then
if itemnumber == nil then
self.page = 1
elseif itemnumber >= 0 then
self.page = self:getPageNumber(itemnumber)
end
self.item_table = new_item_table
self:updateItems()
self:updateItems(1, no_recalculate_dimen)
end
function Menu:getPageNumber(item_number)
if #self.item_table == 0 or item_number == 0 then
return 1
end
return math.ceil(math.min(item_number, #self.item_table) / self.perpage)
end
function Menu:onScreenResize(dimen)
@ -1219,25 +1205,6 @@ function Menu:onShowGotoDialog()
return true
end
function Menu:onWrapFirst()
if self.page > 1 then
self.page = self.page - 1
local end_position = self.perpage
if self.page == self.page_num then
end_position = #self.item_table % self.perpage
end
self:updateItems(end_position)
end
return false
end
function Menu:onWrapLast()
if self.page < self.page_num then
self:onNextPage()
end
return false
end
--[[
override this function to process the item selected in a different manner
]]--
@ -1283,52 +1250,26 @@ function Menu:onMenuHold(item)
end
function Menu:onNextPage()
if self.onNext and self.page == self.page_num - 1 then
self:onNext()
end
if self.page < self.page_num then
self.page = self.page + 1
self:updateItems()
elseif self.page == self.page_num then
-- on the last page, we check if we're on the last item
local end_position = #self.item_table % self.perpage
if end_position == 0 then
end_position = self.perpage
end
if end_position ~= self.selected.y then
self:updateItems(end_position)
end
self.page = 1
self:updateItems()
end
return true
local page = self.page < self.page_num and self.page + 1 or 1 -- cycle for swipes only
return self:onGotoPage(page)
end
function Menu:onPrevPage()
if self.page > 1 then
self.page = self.page - 1
elseif self.page == 1 then
self.page = self.page_num
end
self:updateItems()
return true
local page = self.page > 1 and self.page - 1 or self.page_num -- cycle for swipes only
return self:onGotoPage(page)
end
function Menu:onFirstPage()
self.page = 1
self:updateItems()
return true
return self:onGotoPage(1)
end
function Menu:onLastPage()
self.page = self.page_num
self:updateItems()
return true
return self:onGotoPage(self.page_num)
end
function Menu:onGotoPage(page)
self.page = page
self:updateItems()
self:updateItems(1, true)
return true
end
@ -1336,13 +1277,38 @@ function Menu:onRight()
return self:sendHoldEventToFocusedWidget()
end
function Menu:onShowingReader()
-- Clear the dither flag to prevent it from infecting the queue and re-inserting a full-screen refresh...
self.dithered = nil
end
Menu.onSetupShowReader = Menu.onShowingReader
function Menu:onCloseWidget()
--- @fixme
-- we cannot refresh regionally using the dimen field
-- because some menus without menu title use VerticalGroup to include
-- a text widget which is not calculated into the dimen.
-- For example, it's a dirty hack to use two menus (one being this menu and
-- the other touch menu) in the filemanager in order to capture tap gesture to popup
-- the filemanager menu.
-- NOTE: For the same reason, don't make it flash,
-- because that'll trigger when we close the FM and open a book...
-- Don't do anything if we're in the process of tearing down FM or RD, or if we don't actually have a live instance of 'em...
local FileManager = require("apps/filemanager/filemanager")
local ReaderUI = require("apps/reader/readerui")
if (FileManager.instance and not FileManager.instance.tearing_down)
or (ReaderUI.instance and not ReaderUI.instance.tearing_down) then
UIManager:setDirty(nil, "ui")
end
end
function Menu:onClose()
local table_length = #self.item_table_stack
if table_length == 0 then
if #self.item_table_stack == 0 then
self:onCloseAllMenus()
else
-- back to parent menu
local parent_item_table = table.remove(self.item_table_stack, table_length)
local parent_item_table = table.remove(self.item_table_stack)
self:switchItemTable(parent_item_table.title, parent_item_table)
end
return true
@ -1386,6 +1352,17 @@ function Menu:onSwipe(arg, ges_ev)
end
end
function Menu:onPan(arg, ges_ev)
if ges_ev.mousewheel_direction then
if ges_ev.direction == "north" then
self:onNextPage()
elseif ges_ev.direction == "south" then
self:onPrevPage()
end
end
return true
end
function Menu:onMultiSwipe(arg, ges_ev)
-- For consistency with other fullscreen widgets where swipe south can't be
-- used to close and where we then allow any multiswipe to close, allow any
@ -1408,6 +1385,18 @@ end
function Menu:onLeftButtonHold() -- to be overriden and implemented by the caller
end
function Menu.getItemFontSize(perpage)
-- Get adjusted font size for the given nb of items per page:
-- item font size between 14 and 24 for better matching
return math.floor(24 - ((perpage - 6) * (1/18)) * 10)
end
function Menu.getItemMandatoryFontSize(perpage)
-- Get adjusted font size for the given nb of items per page:
-- "mandatory" font size between 12 and 18 for better matching
return math.floor(18 - (perpage - 6) * (1/3))
end
--- Adds > to touch menu items with a submenu
local arrow_left = "" -- U+25C2 BLACK LEFT-POINTING SMALL TRIANGLE
local arrow_right = "" -- U+25B8 BLACK RIGHT-POINTING SMALL TRIANGLE
@ -1428,18 +1417,6 @@ else
end
end
function Menu.getItemFontSize(perpage)
-- Get adjusted font size for the given nb of items per page:
-- item font size between 14 and 24 for better matching
return math.floor(24 - ((perpage - 6) * (1/18)) * 10)
end
function Menu.getItemMandatoryFontSize(perpage)
-- Get adjusted font size for the given nb of items per page:
-- "mandatory" font size between 12 and 18 for better matching
return math.floor(18 - (perpage - 6) * (1/3))
end
function Menu.getMenuText(item)
local text
if item.text_func then

@ -94,6 +94,7 @@ local Screen = Device.screen
local MultiInputDialog = InputDialog:extend{
fields = nil, -- array, mandatory
input_fields = nil, -- array
focused_field_idx = 1,
description_padding = Size.padding.default,
description_margin = Size.margin.small,
bottom_v_padding = Size.padding.default,
@ -106,22 +107,24 @@ function MultiInputDialog:init()
align = "left",
self.title_bar,
}
local content_width = math.floor(self.width * 0.9)
self.input_field = {}
self.input_fields = {}
local input_description = {}
for i, field in ipairs(self.fields) do
self.input_field[i] = InputText:new{
text = field.text or "",
hint = field.hint or "",
input_type = field.input_type or "string",
text_type = field.text_type,
local input_field_tmp = InputText:new{
text = field.text,
hint = field.hint,
input_type = field.input_type,
text_type = field.text_type, -- "password"
face = self.input_face,
width = math.floor(self.width * 0.9),
focused = i == 1 and true or false,
width = content_width,
idx = i,
focused = i == self.focused_field_idx,
scroll = false,
parent = self,
padding = field.padding or nil,
margin = field.margin or nil,
padding = field.padding,
margin = field.margin,
-- Allow these to be specified per field if needed
alignment = field.alignment or self.alignment,
justified = field.justified or self.justified,
@ -130,7 +133,8 @@ function MultiInputDialog:init()
auto_para_direction = field.auto_para_direction or self.auto_para_direction,
alignment_strict = field.alignment_strict or self.alignment_strict,
}
table.insert(self.layout, #self.layout, {self.input_field[i]})
table.insert(self.input_fields, input_field_tmp)
table.insert(self.layout, { input_field_tmp })
if field.description then
input_description[i] = FrameContainer:new{
padding = self.description_padding,
@ -139,7 +143,7 @@ function MultiInputDialog:init()
TextBoxWidget:new{
text = field.description,
face = Font:getFace("x_smallinfofont"),
width = math.floor(self.width * 0.9),
width = content_width,
}
}
table.insert(VerticalGroupData, CenterContainer:new{
@ -153,9 +157,9 @@ function MultiInputDialog:init()
table.insert(VerticalGroupData, CenterContainer:new{
dimen = Geom:new{
w = self.title_bar:getSize().w,
h = self.input_field[i]:getSize().h,
h = input_field_tmp:getSize().h,
},
self.input_field[i],
input_field_tmp,
})
end
@ -185,7 +189,7 @@ function MultiInputDialog:init()
VerticalGroupData,
}
self._input_widget = self.input_field[1]
self._input_widget = self.input_fields[self.focused_field_idx]
self[1] = CenterContainer:new{
dimen = Geom:new{
@ -201,20 +205,14 @@ function MultiInputDialog:init()
end
--- Returns an array of our input field's *text* field.
function MultiInputDialog:getFields()
local fields = {}
for i, field in ipairs(self.input_field) do
for i, field in ipairs(self.input_fields) do
table.insert(fields, field:getText())
end
return fields
end
--- BEWARE: Live ref to an internal component!
function MultiInputDialog:getRawFields()
return self.input_field
end
function MultiInputDialog:onSwitchFocus(inputbox)
-- unfocus current inputbox
self._input_widget:unfocus()
@ -228,10 +226,27 @@ function MultiInputDialog:onSwitchFocus(inputbox)
-- focus new inputbox
self._input_widget = inputbox
self._input_widget:focus()
self.focused_field_idx = inputbox.idx
-- Make sure we have a (new) visible keyboard
self:onShowKeyboard()
end
return MultiInputDialog
function MultiInputDialog:onKeyboardHeightChanged()
local visible = self:isKeyboardVisible()
local fields = self.input_fields -- backup entered text
self:onClose() -- will close keyboard and save view position
self._input_widget:onCloseWidget() -- proper cleanup of InputText and its keyboard
self:free()
self.keyboard_visible = visible
for i, field in ipairs(self.fields) do -- restore entered text
field.text = fields[i].text
end
self:init()
if self.keyboard_visible then
self:onShowKeyboard()
end
UIManager:setDirty("all", "flashui")
end
return MultiInputDialog

@ -60,13 +60,13 @@ local ProgressWidget = Widget:extend{
_orig_margin_v = nil,
_orig_bordersize = nil,
initial_pos_marker = false, -- overlay a marker at the initial percentage position
inital_percentage = nil,
initial_percentage = nil,
}
function ProgressWidget:init()
if self.initial_pos_marker then
if not self.inital_percentage then
self.inital_percentage = self.percentage
if not self.initial_percentage then
self.initial_percentage = self.percentage
end
self:renderMarkerIcon()
@ -182,11 +182,11 @@ function ProgressWidget:paintTo(bb, x, y)
self.fillcolor)
-- Overlay the initial position marker on top of that
if self.initial_pos_marker then
if self.initial_pos_marker and self.initial_percentage >= 0 then
if self.height <= INITIAL_MARKER_HEIGHT_THRESHOLD then
self.initial_pos_icon:paintTo(bb, Math.round(fill_x + math.ceil(fill_width * self.inital_percentage) - self.height / 4), y - Math.round(self.height / 6))
self.initial_pos_icon:paintTo(bb, Math.round(fill_x + math.ceil(fill_width * self.initial_percentage) - self.height / 4), y - Math.round(self.height / 6))
else
self.initial_pos_icon:paintTo(bb, Math.round(fill_x + math.ceil(fill_width * self.inital_percentage) - self.height / 2), y)
self.initial_pos_icon:paintTo(bb, Math.round(fill_x + math.ceil(fill_width * self.initial_percentage) - self.height / 2), y)
end
end
end
@ -212,8 +212,8 @@ end
function ProgressWidget:setPercentage(percentage)
self.percentage = percentage
if self.initial_pos_marker then
if not self.inital_percentage then
self.inital_percentage = self.percentage
if not self.initial_percentage then
self.initial_percentage = self.percentage
end
end
end

@ -54,7 +54,7 @@ end
function ScreenSaverWidget:onShow()
UIManager:setDirty(self, function()
return "full", self.main_frame.dimen
return Device:hasKaleidoWfm() and "color" or "full", self.main_frame.dimen
end)
return true
end

@ -1,6 +1,7 @@
local BD = require("ui/bidi")
local ButtonDialog = require("ui/widget/buttondialog")
local DataStorage = require("datastorage")
local Device = require("device")
local GestureRange = require("ui/gesturerange")
local InputContainer = require("ui/widget/container/inputcontainer")
local UIManager = require("ui/uimanager")
@ -14,6 +15,9 @@ local Screenshoter = InputContainer:extend{
}
function Screenshoter:init()
self:registerKeyEvents()
if not Device:isTouchDevice() then return end
local diagonal = math.sqrt(Screen:getWidth()^2 + Screen:getHeight()^2)
self.ges_events = {
TapDiagonal = {
@ -79,7 +83,7 @@ function Screenshoter:onScreenshot(screenshot_name, caller_callback)
end,
},
{
text = _("Set as screensaver"),
text = _("Set as wallpaper"),
callback = function()
G_reader_settings:saveSetting("screensaver_type", "image_file")
G_reader_settings:saveSetting("screensaver_image", screenshot_name)
@ -117,6 +121,10 @@ function Screenshoter:chooseFolder()
filemanagerutil.showChooseDialog(title_header, caller_callback, current_path, default_path)
end
function Screenshoter:onKeyPressShoot()
return self:onScreenshot()
end
function Screenshoter:onTapDiagonal()
return self:onScreenshot()
end
@ -125,4 +133,22 @@ function Screenshoter:onSwipeDiagonal()
return self:onScreenshot()
end
function Screenshoter:registerKeyEvents()
if Device:hasKeyboard() then
self.key_events.KeyPressShoot = {
{ "Alt", "Shift", "G" }, -- same as stock Kindle firmware
event = "KeyPressShoot",
}
elseif Device:hasScreenKB() then
-- kindle 4 case: same as stock firmware.
self.key_events.KeyPressShoot = {
{ "ScreenKB", "Menu" },
event = "KeyPressShoot",
}
-- unable to add other non-touch devices as simultaneous key presses won't work without modifiers
end
end
Screenshoter.onPhysicalKeyboardConnected = Screenshoter.registerKeyEvents
return Screenshoter

@ -2,6 +2,7 @@ local BD = require("ui/bidi")
local Blitbuffer = require("ffi/blitbuffer")
local BottomContainer = require("ui/widget/container/bottomcontainer")
local Button = require("ui/widget/button")
local ButtonDialog = require("ui/widget/buttondialog")
local CenterContainer = require("ui/widget/container/centercontainer")
local CheckMark = require("ui/widget/checkmark")
local Device = require("device")
@ -132,7 +133,7 @@ local SortWidget = FocusManager:extend{
-- table of items to sort
item_table = nil, -- mandatory (array)
callback = nil,
sort_disabled = false
sort_disabled = false,
}
function SortWidget:init()
@ -152,6 +153,7 @@ function SortWidget:init()
self.key_events.Close = { { Device.input.group.Back } }
self.key_events.NextPage = { { Device.input.group.PgFwd } }
self.key_events.PrevPage = { { Device.input.group.PgBack } }
self.key_events.ShowWidgetMenu = { { "Menu" } }
end
if Device:isTouchDevice() then
self.ges_events.Swipe = {
@ -272,6 +274,11 @@ function SortWidget:init()
}
table.insert(self.layout, {
self.footer_cancel,
self.footer_first_up,
self.footer_left,
self.footer_page,
self.footer_right,
self.footer_last_down,
self.footer_ok,
})
local bottom_line = LineWidget:new{
@ -294,6 +301,8 @@ function SortWidget:init()
bottom_line_color = Blitbuffer.COLOR_DARK_GRAY,
bottom_line_h_padding = padding,
title = self.title,
left_icon = not self.sort_disabled and "appbar.menu",
left_icon_tap_callback = function() self:showMenu() end,
close_callback = function() self:onClose() end,
show_parent = self,
}
@ -338,24 +347,24 @@ function SortWidget:init()
end
function SortWidget:nextPage()
local new_page = math.min(self.show_page+1, self.pages)
if new_page > self.show_page then
self.show_page = new_page
if self.marked > 0 then
if self.show_page < self.pages then
self.show_page = self.show_page + 1
if self.marked > 0 then -- put selected item first in the page
self:moveItem(self.items_per_page * (self.show_page - 1) + 1 - self.marked)
else
self:_populateItems()
end
self:_populateItems()
end
end
function SortWidget:prevPage()
local new_page = math.max(self.show_page-1, 1)
if new_page < self.show_page then
self.show_page = new_page
if self.marked > 0 then
if self.show_page > 1 then
self.show_page = self.show_page - 1
if self.marked > 0 then -- put selected item first in the page
self:moveItem(self.items_per_page * (self.show_page - 1) + 1 - self.marked)
else
self:_populateItems()
end
self:_populateItems()
end
end
@ -472,6 +481,68 @@ function SortWidget:onSwipe(arg, ges_ev)
end
end
function SortWidget:onShowWidgetMenu()
self:showMenu()
end
function SortWidget:showMenu()
local dialog
local buttons = {
{{
text = _("Sort A to Z"),
align = "left",
callback = function()
UIManager:close(dialog)
self:sortItems("strcoll")
end,
}},
{{
text = _("Sort Z to A"),
align = "left",
callback = function()
UIManager:close(dialog)
self:sortItems("strcoll", true)
end,
}},
{{
text = _("Sort A to Z (natural)"),
align = "left",
callback = function()
UIManager:close(dialog)
self:sortItems("natural")
end,
}},
{{
text = _("Sort Z to A (natural)"),
align = "left",
callback = function()
UIManager:close(dialog)
self:sortItems("natural", true)
end,
}},
}
dialog = ButtonDialog:new{
shrink_unneeded_width = true,
buttons = buttons,
anchor = function()
return self.title_bar.left_button.image.dimen
end,
}
UIManager:show(dialog)
end
function SortWidget:sortItems(collate, reverse_collate)
if not self.orig_item_table then
self.orig_item_table = util.tableDeepCopy(self.item_table)
end
local FileChooser = require("ui/widget/filechooser")
local sort_func = FileChooser:getSortingFunction(FileChooser.collates[collate], reverse_collate)
table.sort(self.item_table, sort_func)
self.show_page = 1
self.marked = 1 -- enable cancel button
self:_populateItems()
end
function SortWidget:onClose()
UIManager:close(self)
UIManager:setDirty(nil, "ui")

@ -444,6 +444,15 @@ function TextViewer:onForwardingPan(arg, ges)
end
function TextViewer:onForwardingPanRelease(arg, ges)
-- Allow scrolling with the mousewheel
if ges.from_mousewheel and ges.relative and ges.relative.y then
if ges.relative.y < 0 then
self.scroll_text_w:scrollText(1)
elseif ges.relative.y > 0 then
self.scroll_text_w:scrollText(-1)
end
return true
end
-- We can forward onMovablePanRelease() does enough checks
return self.movable:onMovablePanRelease(arg, ges)
end

@ -511,6 +511,7 @@ function TouchMenu:init()
}
self.key_events.Back = { { Input.group.Back } }
self.key_events.Close = { { "Menu" } }
if Device:hasFewKeys() then
self.key_events.Back = { { "Left" } }
end

@ -54,6 +54,9 @@ function TrapWidget:init()
SwipeDismiss = {
GestureRange:new{ ges = "swipe", range = full_screen, }
},
PanReleaseDismiss = { -- emitted on mousewheel event
GestureRange:new{ ges = "pan_release", range = full_screen, }
},
}
end
if self.text then
@ -139,6 +142,10 @@ function TrapWidget:onSwipeDismiss(_, ev)
return self:_dismissAndResend("Gesture", ev)
end
function TrapWidget:onPanReleaseDismiss(_, ev)
return self:_dismissAndResend("Gesture", ev)
end
function TrapWidget:onShow()
if self.frame then
UIManager:setDirty(self, function()

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save