Commit graph

146 commits

Author SHA1 Message Date
Tim Schumacher 82a152b696 LibGfx: Remove try_ prefix from bitmap creation functions
Those don't have any non-try counterpart, so we might as well just omit
it.
2023-01-26 20:24:37 +00:00
Liav A e241b47fee Userland: Remove a bunch of unveil calls on /sys/kernel/processes
These are not needed anymore since the introduction of the new
get_root_session_id syscall.
2023-01-13 13:41:30 +01:00
Karol Kosek d4367f42ba PDFViewer: Port to Core::Stream::File 2023-01-10 22:15:23 +00:00
Karol Kosek 247db3fdd0 LibFileSystemAccessClient: Rename try_* functions to try_*_deprecated
These functions return the deprecated `Core::File` class, so let's mark
it as such to avoid possible confusion between future non try_*
functions which will use Core::Stream family classes and to possibly
grab someone's attention. :^)
2023-01-07 10:53:43 +00:00
Sam Atkins 0c24522635 LibGUI+Everywhere: Use fallible Window::set_main_widget() everywhere :^)
Rip that bandaid off!

This does the following, in one big, awkward jump:
- Replace all uses of `set_main_widget<Foo>()` with the `try` version.
- Remove `set_main_widget<Foo>()`.
- Rename the `try` version to just be `set_main_widget` because it's now
  the only one.

The majority of places that call `set_main_widget<Foo>()` are inside
constructors, so this unfortunately gives us a big batch of new
`release_value_but_fixme_should_propagate_errors()` calls.
2023-01-06 13:36:02 -07:00
Rodrigo Tobar b406f1d5a4 PDFViewer: Inform users of underlying issue when loading document
While this is not super useful to end users, it's still better than the
simpler, generic "failed to load" error message.
2023-01-06 18:06:41 +01:00
Ben Wiederhake b83cb09db1 Everywhere: Fix badly-formatted includes
In 7c5e30daaa, the focus was "only" on
Userland/Libraries/, whereas this commit cleans up the remaining
headers in the repo, and any new badly-formatted include.
2023-01-02 11:06:15 -05:00
Rodrigo Tobar 89061883f2 PDFViewer: Prompt password for encrypted documents
This tackles a FIXME, but also makes sense to implement only now that
the SecurityHandler logic has been fixed. When a Document is created an
automatic attempt is made to provide the empty string as the password;
even if this attempt failed the SecurityHandler still reported it had a
user password, hence we never arrived to the VERIFY_NOT_REQUIRED line
this commit is changing.
2022-12-20 10:28:58 +01:00
Rodrigo Tobar b8dc05a08e PDFViewer: Fix indexing error in ErrorsView
I confused myself when implementing this, plus I tested using pages that
had errors in pages 1 and 2, so the index and the number of the page
(internally represented as 0-indexed) was always the same. When opening
files with errors on higher pages it became evident that there was an
issue with how I was reading the errors per page from the corresponding
ModelIndex object.
2022-12-20 10:28:58 +01:00
Rodrigo Tobar d116b9a8c6 PDFViewer: Move to page when outline item is selected 2022-12-17 19:40:52 +01:00
Rodrigo Tobar d739877807 PDFViewer: Inform about selections on Outline view
Selecting an Outline Item from the Outline view informs via callback the
corresponding Destination that has been selected. This will be used to
move the application to the corresponding page/section/etc.
2022-12-17 19:40:52 +01:00
Rodrigo Tobar aaa210e6db PDFViewer: Show page numbers in Outline TreeView
This is a nice addition to the outline view, which previously simply
displayed the titles of each section. Pages are shown in the first
column, but the tree is expanded via the second column, where the title
is.
2022-12-17 19:40:52 +01:00
Rodrigo Tobar c76564b533 PDFViewer: Fix parent_index() implementation in OutlineModel
The previous implementation had some repeated code, and wasn't really
working (because the OutlineItem.parent member was never populated). In
fact, when navigating with the up/down arrows in the associted TreeView
one could experience some funky behavior.

Now that we store OutlineItem's parents, we are fixing the
implementation for parent_index(), which was comparing the parent
siblings against the item's outline item instead of to its parent.
2022-12-17 19:40:52 +01:00
Rodrigo Tobar 2ea8d2547e PDFViewer: Propagate errors from OutlineModel construction
This follows the same idea that Andreas was doing in this latest videos,
where construction-time TRY()s were not present but should have been.
Like Andreas did, moving the initialisation of such fields to the
factory function, which then returns ErrorOr solves the issue.
2022-12-17 19:40:52 +01:00
Rodrigo Tobar cb2cf6de99 PDFViewer: Perform standard error handling when opening files
The previous implementation of open_file had a lambda that was used to
inspect the call of ErrorOr-returning calls. This was a non-standard way
of doing this though, as the more usual and clearer way is to have an
inner function that returns ErrorOr, then handle any incoming errors on
the top level function.

This commit adds a try_open_file function, where all the logic occurs,
and all the failure-producing steps are simplied TRY'ed. The top level
open_file function takes that result and does what the lambda previously
did: showing a message box with the actual error.
2022-12-17 19:40:52 +01:00
Rodrigo Tobar d4ecdf3ced PDFViewer: Avoid errors due to copying of ErrorOr
The handle_error took PDFErrorOr<T> objects by value, meaning that their
inner values (the error or value stored in the underlying Variant) were
somehow copied over. In the first instance where this lambda is called
with T = NonnullRefPtr, resulting in funky behavior (invalid
NonnullRefPtr state with a VALIDATE fail): if there is no error then the
PDFErrorOr<T> copy is destroyed, which might be causing the underlying
NonnullRefPtr to be destroyed, but somehow the original in the caller
context gets affected and fails verification.

The solution seems simple anyway: just pass the value by reference
(lvalue or rvalue) so the original object can be used directly, avoiding
destruction.
2022-12-16 10:04:23 +01:00
Rodrigo Tobar 124ab5bec6 PDFViewer: Remove unnecessary ternary operation 2022-12-16 10:04:23 +01:00
Rodrigo Tobar 6d0869c14a PDFViewer: Add TreeView to communicate rendering errors
Now that the rendering process communicates all errors upstream, and
PDFViewer has a way to tap into those errors as they occur, we can
visualise them more neatly.

This commit adds a TreeView that we populate with the errors stemming
from the rendering process. The TreeView has two levels: at the top sit
pages where errors can be found, and under each page we can see the
errors that have been found on that page. The TreeView sits below the
main PDF rendering.
2022-12-16 10:04:23 +01:00
Rodrigo Tobar e87fecf710 LibPDF: Switch to best-effort PDF rendering
The current rendering routine aborts as soon as an error is found during
rendering, which potentially severely limits the contents we show on
screen. Moreover, whenever an error happens the PDFViewer widget shows
an error dialog, and doesn't display the bitmap that has been painted so
far.

This commit improves the situation in both fronts, implementing
rendering now with a best-effort approach. Firstly, execution of
operations isn't halted after an operand results in an error, but
instead execution of all operations is always attempted, and all
collected errors are returned in bulk. Secondly, PDFViewer now always
displays the resulting bitmap, regardless of error being produced or
not. To communicate errors, an on_render_errors callback has been added
so clients can subscribe to these events and handle them as appropriate.
2022-12-16 10:04:23 +01:00
Rodrigo Tobar 67b50d7994 PDFViewer: Let users change image rendering
A new checkbox in the toolbar now allows users toggle image rendering. A
corresponding Config option makes this setting non-volatile. To void
clashing with the previous "show_clipping_paths" option when caching a
Page, we now use the RenderingPreferences.hash() and the pair_int_hash
funcitons to compute a unique key into the page cache map for a given
RenderingPreferences and zoom level.
2022-12-10 10:49:03 +01:00
Linus Groh 57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh 6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Rodrigo Tobar 44c518e767 PDFViewer: Show single/multi page actions on toolbar
These actions were being constructed, and they work, but were not shown
in the toolbar. Adding them will allow users to actually use them, as
well as pick up any bugs they might have.
2022-11-25 23:03:24 +01:00
Rodrigo Tobar cbb373e135 PDFViewer: Toggle prev/next page actions when page changes
These actions were not updated accordingly when one scrolled through the
document, and thus one could accidentally, for example, move to the next
page when standing on the last, which caused a crash.

This commit fixes that behavior, toggling the actions' enabled status
depending on the new page being displayed.
2022-11-25 23:03:24 +01:00
Rodrigo Tobar a740423e23 PDFViewer: Prevent infinity recursion
When removing all contents from the NumericInput box in PDFViewer the
callback set the (empty) text again back in the box, triggering another
callback in a recursive, non-stopping fashion. Not setting the text back
in the box avoids the problem.
2022-11-25 23:03:24 +01:00
Rodrigo Tobar bc7da24fe6 PDFViewer: Let users change clipping paths visibility
Now that the Renderer accepts preferences, PDFViewer can offer ways for
changing these preferences. The first step in this direction is to add a
checkbox that allows toggling whether clipping paths are visible or not.
A Config item has also been added to remember this setting.
2022-11-25 23:03:24 +01:00
Julian Offenhäuser 0308300b78 PDFViewer: Take the mousewheel delta into account for scrolling
We now respect the system-wide setting for scroll speed, where we would
previously use a fixed step.
2022-11-19 15:42:08 +01:00
Julian Offenhäuser 9b1331a984 PDFViewer: Simplify user-facing error messages
We now show a simple, if less helpful, message to the user and print
the verbose error message to serial instead.
2022-11-19 15:42:08 +01:00
Julian Offenhäuser e782d03f96 PDFViewer: Invalidate document when a page fails to load
This fixes an issue where we would show an error message on every
subsequent paint event, making it impossible to close or use the
application further.

Some more architectural work is needed if we want to invalidate the
sidebar entries as well.
2022-11-19 15:42:08 +01:00
Tim Schumacher ce2f1b845f Everywhere: Mark dependencies of most targets as PRIVATE
Otherwise, we end up propagating those dependencies into targets that
link against that library, which creates unnecessary link-time
dependencies.

Also included are changes to readd now missing dependencies to tools
that actually need them.
2022-11-01 14:49:09 +00:00
Liav A 5dfb2b18f3 Applications: Use new global variables at /sys/kernel/ directory 2022-10-25 15:33:34 -06:00
demostanis 34acae90c7 Userland: Let applications make use of make_command_palette_action() 2022-10-25 10:21:18 +01:00
Timothy Flynn 7cab86ad28 Userland: Unveil /proc/all in applications which require it
These were missed in 7af5eef. It is needed for any application using
e.g. FileSystemAccessServer.
2022-10-03 17:09:21 +01:00
Timothy Flynn 25e0ab3ee4 Userland: Tighten promises by removing 'proc' where it isn't used
This is a partial revert of commit 7af5eef. After 97d15e9, the 'proc'
promise is not needed for operations using getsid().

This also fixes launching several applications in which 7af5eef added
the 'proc' promise only in the second call to pledge().
2022-10-03 17:09:21 +01:00
Peter Elliott 7af5eef0dd SystemServer+LoginServer+Userland: Switch to sid-based sockets
This commit does three things atomically:
- switch over Core::Account+SystemServer+LoginServer to sid based socket
  names.
- change socket names with %uid to %sid.
- add/update necessary pledges and unveils.

Userland: Switch over servers to sid based sockets

Userland: Properly pledge and unveil for sid based sockets
2022-10-03 11:11:29 +02:00
thankyouverycool cce9172cd4 Applications+DevTools: Remove fixed sizes from Splitters
And adjust some GML properties. Since a808cfa, splitters grow
opportunistically. Setting them to fixed sizes now quite literally
fixes them in place. Fixes immovable splitters missed in the
aforementioned commit.
2022-08-30 16:28:44 +01:00
Lucas CHOLLET e8115bfdb1 Base: Launch FileSystemAccessServer at session start-up 2022-08-14 21:52:35 +01:00
sin-ack 3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
Simon Wanner 206d6ece55 LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
Matthew Olsson 195572dd2a PDFViewer: Propagate more errors 2022-04-04 14:59:37 +02:00
Matthew Olsson 1fdcf57c0b PDFViewer: Autosize page label 2022-04-04 14:59:37 +02:00
Matthew Olsson baac720e13 PDFViewer: Respect page navigation features in multi-page mode
This includes the text box and the page up/down arrows.
2022-04-04 14:59:37 +02:00
Matthew Olsson 3ecb41b7d9 PDFViewer: Support a continuous page view mode 2022-04-04 14:59:37 +02:00
Matthew Olsson 091c2cfdca PDFViewer: Add page mode option 2022-04-04 14:59:37 +02:00
Matthew Olsson c39718ca81 PDFViewer: Don't change pages on horizontal scroll
This was a bit jarring, and didn't align with the behavior of other PDF
renderers.
2022-04-04 14:59:37 +02:00
Matthew Olsson b2f79a74d4 PDFViewer: Clear rendered page cache on application resize
When resizing the application, the pages are expected to grow or shrink
proportionally. This means that after a resize, we need to rerender
every page.
2022-04-04 14:59:37 +02:00
Idan Horowitz 086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Matthew Olsson 698fb3957a LibPDF: Fix security-handler-related nullptr regression 2022-03-31 18:10:45 +02:00
Matthew Olsson 6bed20f456 PDFViewer: Use ArgsParser 2022-03-31 18:10:45 +02:00
Matthew Olsson 5b316462b2 LibPDF: Add implementation of the Standard security handler
Security handlers manage encryption and decription of PDF files. The
standard security handler uses RC4/MD5 to perform its crypto (AES as
well, but that is not yet implemented).
2022-03-29 02:52:57 +02:00
Matthew Olsson b240d23a87 LibPDF: Propagate errors in Renderer/PDFViewer 2022-03-07 10:53:57 +01:00
Matthew Olsson 73cf8205b4 LibPDF: Propagate errors in Parser and Document 2022-03-07 10:53:57 +01:00
Lenny Maiorani 1dd70a6f49 Applications: Change static constexpr variables to constexpr
Function-local `static constexpr` variables can be `constexpr`. This
can reduce memory consumption, binary size, and offer additional
compiler optimizations.
2022-02-28 13:54:27 +01:00
Mustafa Quraish effb19f996 PDFViewer: Use FileSystemAccessClient::try_* APIs 2022-01-20 10:39:12 +01:00
Dmitry Petrov 1662213737 Userland: Add horizontal mouse scroll support 2022-01-20 10:37:52 +01:00
creator1creeper1 a76e97df64 PDFViewer: Propagate errors using try_set_main_widget in main 2022-01-09 00:56:11 +01:00
Marcus Nilsson eb97617ff0 PDFViewer: Add actions to rotate the displayed PDF
This implements the rotate cw/ccw actions in PDFViewer.
Since the rendered pages are stored in a HashMap for caching,
the bitmap is wrapped in a struct with the current rotation.
This way the caching works as expected while zooming, and a new bitmap
is rendered when the page is rotated.
2022-01-06 21:25:02 +01:00
Marcus Nilsson 56bec4968c PDFViewer: Enable panning with middle mouse button
Enable the use of the middle mouse button for panning in PDFViewer.
2022-01-06 21:25:02 +01:00
Marcus Nilsson 3af71c406d PDFViewer: Add zoom in/out/reset menu actions
Make PDFViewer::zoom_in() & ::zoom_out() public and add menu and toolbar
actions. Also add an action for zoom reset.
2022-01-06 21:25:02 +01:00
Marcus Nilsson 45085122ee PDFViewer: Fix sidebar toggle logic
The open_outline_action logic was backwards resulting in it
being closed on the first click and opened on the second,
and opposite if document->outline() was true.

There was also a collision with the Ctrl+O shortcut for opening a
document, this changes it to Ctrl+S instead.

This commit also changes the wording to 'Toogle' instead of 'Open/Close'
since the text wasn't updated as expected, and lastly, add a View menu
with the action.
2022-01-06 21:25:02 +01:00
Elyse 086615535f Everywhere: Use 'decrease_slider_by()' method from AbstractSlider
The same idea as 'increase_slider_by()', it helps us to avoid repeating
the pattern 'set_value(value() - delta)'.
2021-12-30 14:31:50 +01:00
Elyse d53e1fa1fa Everywhere: Use 'increase_slider_by()' method from AbstractSlider
This method help us to avoid repeating the pattern
'set_value(value() + delta)'.
2021-12-30 14:31:50 +01:00
Andreas Kling e815bf5d1f PDFViewer: Add a basic set of pledges 2021-12-25 10:58:30 +01:00
Andreas Kling 21a5fb0fa2 LibCore+LibSystem: Move syscall wrappers from LibSystem to LibCore
With this change, System::foo() becomes Core::System::foo().

Since LibCore builds on other systems than SerenityOS, we now have to
make sure that wrappers work with just a standard C library underneath.
2021-11-23 11:33:36 +01:00
Mustafa Quraish 4d302e0e88 Everywhere: Use Application::construct() with Main::Arguments directly
Use the updated API everywhere we are currently manually passing in
`arguments.argc` and `arguments.argv`.
2021-11-22 21:13:42 -08:00
Pascal Puffke 61408e2397 PDFViewer: Port to LibMain 2021-11-22 23:56:22 +01:00
Andreas Kling 0de33b3d6c LibGfx: Use ErrorOr<T> for Bitmap::try_create()
Another one that was used in a fajillion places.
2021-11-08 00:35:27 +01:00
Andreas Kling 235f39e449 LibGfx: Use ErrorOr<T> for Bitmap::try_load_from_file()
This was used in a lot of places, so this patch makes liberal use of
ErrorOr<T>::release_value_but_fixme_should_propagate_errors().
2021-11-08 00:35:27 +01:00
Andreas Kling 69c4614a94 LibGfx: Use ErrorOr<T> for Bitmap::rotated() 2021-11-08 00:35:27 +01:00
Ben Wiederhake 465af4c4d4 Applications: Fix visibility of Object-derivative constructors
Derivatives of Core::Object should be constructed through
ClassName::construct(), to avoid handling ref-counted objects with
refcount zero. Fixing the visibility means that misuses like this are
more difficult.
2021-11-02 22:56:53 +01:00
Mustafa Quraish 0f749681a9 Everywhere: Use my fancy new serenityos.org email :^) 2021-09-13 20:51:50 +00:00
Mustafa Quraish 63ff5873d8 PDFViewer: Open CLI files through FileSystemAccessServer without prompt
Use `request_file_read_only_approved()` for the file (if any) is
specified through a command line argument.
2021-09-10 20:46:50 +04:30
Mustafa Quraish eae21c7e31 PDFViewer: Use FileSystemAccessClient to open files 2021-09-04 03:32:30 +02:00
sin-ack e11d177618 Userland+LibGUI: Add shorthand versions of the Margins constructor
This allows for typing [8] instead of [8, 8, 8, 8] to specify the same
margin on all edges, for example. The constructors follow CSS' style of
specifying margins. The added constructors are:

- Margins(int all): Sets the same margin on all edges.
- Margins(int vertical, int horizontal): Sets the first argument to top
  and bottom margins, and the second argument to left and right margins.
- Margins(int top, int vertical, int bottom): Sets the first argument to
  the top margin, the second argument to the left and right margins,
  and the third argument to the bottom margin.
2021-08-18 10:30:50 +02:00
sin-ack ca2c81251a Everywhere: Replace Model::update() with Model::invalidate()
Most of the models were just calling did_update anyway, which is
pointless since it can be unified to the base Model class. Instead, code
calling update() will now call invalidate(), which functions identically
and is more obvious in what it does.

Additionally, a default implementation is provided, which removes the
need to add empty implementations of update() for each model subclass.

Co-Authored-By: Ali Mohammad Pur <ali.mpfard@gmail.com>
2021-08-06 19:14:31 +02:00
Andreas Kling 687a12d7fb Userland: Add GUI::Window::add_menu() and use it everywhere
Applications previously had to create a GUI::Menubar object, add menus
to it, and then call GUI::Window::set_menubar().

This patch introduces GUI::Window::add_menu() which creates the menubar
automatically and adds items to it. Application code becomes slightly
simpler as a result. :^)
2021-07-21 21:24:26 +02:00
Andreas Kling c7d891765c LibGfx: Use "try_" prefix for static factory functions
Also mark them as [[nodiscard]].
2021-07-21 18:02:15 +02:00
FalseHonesty 4f0a75224c PDFViewer: Update the page number when scrolling between pages 2021-06-22 06:26:44 +04:30
Gunnar Beutner 631d36fd98 Everywhere: Add component declarations
This adds component declarations so that users can select to not build
certain parts of the OS.
2021-06-17 11:03:51 +02:00
Matthew Olsson 69410d7f4e PDFViewer: Switch back to up/down page icons
This time I remembered to actually commit the image files, oops :^)
2021-06-12 22:45:01 +04:30
Matthew Olsson e7b70a1435 PDFViewer: Display error dialog if necessary instead of crashing 2021-06-12 22:45:01 +04:30
Matthew Olsson 1ef5071d1b LibPDF: Harden the document/parser against errors 2021-06-12 22:45:01 +04:30
Linus Groh d2149c153c PDFViewer: Reset current page number to 1 when opening a file
Also use set_current_number() instead of set_text(), so we don't have to
create a string from the number ourselves.
2021-05-27 18:49:49 +01:00
Linus Groh a8d47d648c PDFViewer: Enable previous/next buttons conditionally
Instead of having both always enabled once a document is loaded, update
them on each page change and disable if appropriate.
2021-05-27 18:47:44 +01:00
Linus Groh dbb0ee0704 PDFViewer: Fix previous/next page toolbar button icons
go-up.png and go-down.png don't exist (and would look silly here, with
the buttons being next to each other horizontally). Use go-back.png and
go-forward.png instead.
2021-05-27 18:43:23 +01:00
Linus Groh 6b0c2d5de6 PDFViewer: Add a Help menu 2021-05-27 18:10:34 +01:00
Linus Groh cde5107f3d PDFViewer: Add separator before quit menu action 2021-05-27 18:09:37 +01:00
Linus Groh 209bfbaaa4 PDFViewer: Show app name as "PDF Viewer" when a file is loaded 2021-05-27 18:08:49 +01:00
Matthew Olsson cf3eb27108 PDFViewer: Add a toolbar
The toolbar has an option to toggle the sidebar, a number input to
set the current page, and two buttons to go up and down by one page
2021-05-25 00:24:09 +04:30
Matthew Olsson cea7dbce42 PDFViewer: Add a tab bar with outlines and thumbnails
Outlines are in theory implemented (though I'm having trouble finding
a simple PDF with outlines to test it on), and thumbnails are not.
2021-05-25 00:24:09 +04:30
Andreas Kling 076018b74b PDFViewer: Ignore wheel events when there is no document loaded 2021-05-18 21:25:35 +02:00
Andreas Kling df29d58e19 PDFViewer+Base: Display application title as "PDF Viewer"
This matches other applications in the system. :^)
2021-05-18 21:00:32 +02:00
Matthew Olsson fe2d4d85c4 PDFViewer: Add some padding to the outside of the page 2021-05-18 16:35:23 +02:00
Matthew Olsson c3c2121b57 PDFViewer: Allow zooming in and out + scrolling
When holding ctrl and scrolling, the page will be zoomed in an out.
When zoomed in on a page, scrolling with move vertically up and down
the page (or horizontally if shift is being held).

In order to speed up zooming, zoomed bitmaps are cached per-page at
each distinct zoom level. This cache is cleared every 30 seconds to
prevent OOM problems.
2021-05-18 16:35:23 +02:00
Matthew Olsson d5f94aaa7b LibPDF/PDFViewer: Support rotated pages 2021-05-18 16:35:23 +02:00
Matthew Olsson f7ea1eb610 Applications: Add a very simple PDFViewer 2021-05-18 16:35:23 +02:00