summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorJunior Rantila <junior.rantila@gmail.com>2023-03-20 23:49:25 +0100
committerSam Atkins <atkinssj@gmail.com>2023-03-21 08:45:58 +0000
commitf0ceaca2f46f0c1fec14a7202283223365c3330e (patch)
tree306a9612f7f46af59516aca1b6af0f0bf3a1ece6 /Userland
parent03c225b02309872398f977c9a25cc0ea75aff77b (diff)
downloadserenity-f0ceaca2f46f0c1fec14a7202283223365c3330e.zip
VideoPlayer: Add drag and drop support
This patch makes it so that we view clips by dropping them on an open VideoPlayer window.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/VideoPlayer/CMakeLists.txt2
-rw-r--r--Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp21
-rw-r--r--Userland/Applications/VideoPlayer/VideoPlayerWidget.h2
3 files changed, 24 insertions, 1 deletions
diff --git a/Userland/Applications/VideoPlayer/CMakeLists.txt b/Userland/Applications/VideoPlayer/CMakeLists.txt
index 86844c266d..20aaabd61d 100644
--- a/Userland/Applications/VideoPlayer/CMakeLists.txt
+++ b/Userland/Applications/VideoPlayer/CMakeLists.txt
@@ -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)
diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
index f390397ad4..a3315fac00 100644
--- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
+++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
@@ -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();
diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
index 3202430603..b99e8a2fae 100644
--- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
+++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
@@ -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;