| 
									
										
										
										
											2024-04-12 15:15:09 -06:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Application.h"
 | 
					
						
							|  |  |  | #include "StringUtils.h"
 | 
					
						
							| 
									
										
										
										
											2024-04-26 18:53:55 -06:00
										 |  |  | #include "TaskManagerWindow.h"
 | 
					
						
							| 
									
										
										
										
											2024-04-12 15:15:09 -06:00
										 |  |  | #include <LibWebView/URL.h>
 | 
					
						
							|  |  |  | #include <QFileOpenEvent>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Ladybird { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Application::Application(int& argc, char** argv) | 
					
						
							|  |  |  |     : QApplication(argc, argv) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 18:53:55 -06:00
										 |  |  | Application::~Application() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     close_task_manager_window(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-12 15:15:09 -06:00
										 |  |  | 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()); | 
					
						
							| 
									
										
										
										
											2024-04-15 17:39:48 -06:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2024-04-12 15:15:09 -06:00
										 |  |  |     } | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return QApplication::event(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 18:53:55 -06:00
										 |  |  | void Application::show_task_manager_window() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!m_task_manager_window) { | 
					
						
							|  |  |  |         m_task_manager_window = new TaskManagerWindow(nullptr); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     m_task_manager_window->show(); | 
					
						
							|  |  |  |     m_task_manager_window->activateWindow(); | 
					
						
							|  |  |  |     m_task_manager_window->raise(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Application::close_task_manager_window() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_task_manager_window) { | 
					
						
							|  |  |  |         m_task_manager_window->close(); | 
					
						
							|  |  |  |         delete m_task_manager_window; | 
					
						
							|  |  |  |         m_task_manager_window = nullptr; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-28 13:27:57 -06:00
										 |  |  | BrowserWindow& Application::new_window(Vector<URL::URL> const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, Tab* parent_tab, Optional<u64> page_index) | 
					
						
							| 
									
										
										
										
											2024-04-26 18:53:55 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-05-28 13:27:57 -06:00
										 |  |  |     auto* window = new BrowserWindow(initial_urls, cookie_jar, web_content_options, webdriver_content_ipc_path, parent_tab, move(page_index)); | 
					
						
							| 
									
										
										
										
											2024-04-26 18:53:55 -06:00
										 |  |  |     set_active_window(*window); | 
					
						
							|  |  |  |     window->show(); | 
					
						
							|  |  |  |     window->activateWindow(); | 
					
						
							|  |  |  |     window->raise(); | 
					
						
							|  |  |  |     return *window; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-12 15:15:09 -06:00
										 |  |  | } |