mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
Ladybird: Move QApplication class to its own file
We'll attach some global data to it in an upcoming commit, so it needs to be accessible outside of main.cpp.
This commit is contained in:
parent
5e18d157d0
commit
336b661835
Notes:
sideshowbarker
2024-07-17 22:09:47 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/336b661835 Pull-request: https://github.com/SerenityOS/serenity/pull/23945 Reviewed-by: https://github.com/trflynn89 ✅
@ -114,6 +114,7 @@ set(LADYBIRD_HEADERS
|
||||
if (ENABLE_QT)
|
||||
qt_add_executable(ladybird ${SOURCES})
|
||||
target_sources(ladybird PRIVATE
|
||||
Qt/Application.cpp
|
||||
Qt/AutoComplete.cpp
|
||||
Qt/BrowserWindow.cpp
|
||||
Qt/EventLoopImplementationQt.cpp
|
||||
|
40
Ladybird/Qt/Application.cpp
Normal file
40
Ladybird/Qt/Application.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Application.h"
|
||||
#include "StringUtils.h"
|
||||
#include <LibWebView/URL.h>
|
||||
#include <QFileOpenEvent>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
Application::Application(int& argc, char** argv)
|
||||
: QApplication(argc, argv)
|
||||
{
|
||||
}
|
||||
|
||||
bool Application::event(QEvent* event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::FileOpen: {
|
||||
if (!on_open_file)
|
||||
break;
|
||||
|
||||
auto const& open_event = *static_cast<QFileOpenEvent const*>(event);
|
||||
auto file = ak_string_from_qstring(open_event.file());
|
||||
|
||||
if (auto file_url = WebView::sanitize_url(file); file_url.has_value())
|
||||
on_open_file(file_url.release_value());
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QApplication::event(event);
|
||||
}
|
||||
|
||||
}
|
26
Ladybird/Qt/Application.h
Normal file
26
Ladybird/Qt/Application.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <LibURL/URL.h>
|
||||
#include <QApplication>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
class Application : public QApplication {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Application(int& argc, char** argv);
|
||||
|
||||
virtual bool event(QEvent* event) override;
|
||||
|
||||
Function<void(URL::URL)> on_open_file;
|
||||
};
|
||||
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Application.h"
|
||||
#include "BrowserWindow.h"
|
||||
#include "EventLoopImplementationQt.h"
|
||||
#include "Settings.h"
|
||||
@ -20,8 +21,6 @@
|
||||
#include <LibWebView/Database.h>
|
||||
#include <LibWebView/ProcessManager.h>
|
||||
#include <LibWebView/URL.h>
|
||||
#include <QApplication>
|
||||
#include <QFileOpenEvent>
|
||||
|
||||
#if defined(AK_OS_MACOS)
|
||||
# include <Ladybird/MachPortServer.h>
|
||||
@ -59,42 +58,11 @@ static ErrorOr<void> handle_attached_debugger()
|
||||
return {};
|
||||
}
|
||||
|
||||
class LadybirdApplication : public QApplication {
|
||||
public:
|
||||
LadybirdApplication(int& argc, char** argv)
|
||||
: QApplication(argc, argv)
|
||||
{
|
||||
}
|
||||
|
||||
Function<void(URL::URL)> on_open_file;
|
||||
|
||||
bool event(QEvent* event) override
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::FileOpen: {
|
||||
if (!on_open_file)
|
||||
break;
|
||||
|
||||
auto const& open_event = *static_cast<QFileOpenEvent const*>(event);
|
||||
auto file = ak_string_from_qstring(open_event.file());
|
||||
|
||||
if (auto file_url = WebView::sanitize_url(file); file_url.has_value())
|
||||
on_open_file(file_url.release_value());
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QApplication::event(event);
|
||||
}
|
||||
};
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
AK::set_rich_debug_enabled(true);
|
||||
|
||||
LadybirdApplication app(arguments.argc, arguments.argv);
|
||||
Ladybird::Application app(arguments.argc, arguments.argv);
|
||||
|
||||
Core::EventLoopManager::install(*new Ladybird::EventLoopManagerQt);
|
||||
Core::EventLoop event_loop;
|
||||
|
@ -13,6 +13,7 @@ group("Ladybird") {
|
||||
|
||||
moc_qt_objects("generate_moc") {
|
||||
sources = [
|
||||
"Qt/Application.h",
|
||||
"Qt/AutoComplete.h",
|
||||
"Qt/BrowserWindow.h",
|
||||
"Qt/EventLoopImplementationQtEventTarget.h",
|
||||
@ -85,6 +86,7 @@ executable("ladybird_executable") {
|
||||
configs += [ ":ladybird_qt_components" ]
|
||||
|
||||
sources += [
|
||||
"Qt/Application.cpp",
|
||||
"Qt/AutoComplete.cpp",
|
||||
"Qt/BrowserWindow.cpp",
|
||||
"Qt/EventLoopImplementationQt.cpp",
|
||||
|
Loading…
Reference in New Issue
Block a user