forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
5 changed files
with
71 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2024, Andrew Kaster <[email protected]> | ||
* | ||
* 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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) 2024, Andrew Kaster <[email protected]> | ||
* | ||
* 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; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters