VideoPlayer: Add drag and drop support

This patch makes it so that we view clips by dropping them on an open
VideoPlayer window.
This commit is contained in:
Junior Rantila 2023-03-20 23:49:25 +01:00 committed by Sam Atkins
parent 03c225b023
commit f0ceaca2f4
Notes: sideshowbarker 2024-07-16 23:52:10 +09:00
3 changed files with 24 additions and 1 deletions

View file

@ -17,4 +17,4 @@ set(GENERATED_SOURCES
)
serenity_app(VideoPlayer ICON app-video-player)
target_link_libraries(VideoPlayer PRIVATE LibVideo LibAudio LibCore LibGfx LibGUI LibMain)
target_link_libraries(VideoPlayer PRIVATE LibVideo LibAudio LibCore LibGfx LibGUI LibMain LibFileSystemAccessClient)

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/Action.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/FilePicker.h>
@ -265,6 +266,26 @@ void VideoPlayerWidget::event(Core::Event& event)
Widget::event(event);
}
void VideoPlayerWidget::drop_event(GUI::DropEvent& event)
{
event.accept();
window()->move_to_front();
if (event.mime_data().has_urls()) {
auto urls = event.mime_data().urls();
if (urls.is_empty())
return;
if (urls.size() > 1) {
GUI::MessageBox::show_error(window(), "VideoPlayer can only view one clip at a time!"sv);
return;
}
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), urls.first().path());
if (response.is_error())
return;
open_file(response.value().filename());
}
}
void VideoPlayerWidget::cycle_sizing_modes()
{
auto sizing_mode = m_video_display->sizing_mode();

View file

@ -53,6 +53,8 @@ private:
void event(Core::Event&) override;
virtual void drop_event(GUI::DropEvent&) override;
DeprecatedString m_path;
RefPtr<VideoFrameWidget> m_video_display;