2020-03-19 18:55:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019-2020, Ryan Grieb <ryan.m.grieb@gmail.com>
|
2023-11-17 20:04:40 +00:00
|
|
|
* Copyright (c) 2023, David Ganz <david.g.ganz@gmail.com>
|
2020-03-19 18:55:25 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-19 18:55:25 +00:00
|
|
|
*/
|
|
|
|
|
2023-06-29 01:17:31 +00:00
|
|
|
#include "CalendarWidget.h"
|
2022-07-15 23:33:39 +00:00
|
|
|
#include <LibConfig/Client.h>
|
2023-06-29 01:17:31 +00:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2022-01-04 17:14:56 +00:00
|
|
|
#include <LibCore/System.h>
|
2023-06-29 01:17:31 +00:00
|
|
|
#include <LibFileSystem/FileSystem.h>
|
|
|
|
#include <LibFileSystemAccessClient/Client.h>
|
2020-03-10 21:41:48 +00:00
|
|
|
#include <LibGUI/Action.h>
|
2021-03-30 00:43:40 +00:00
|
|
|
#include <LibGUI/ActionGroup.h>
|
2020-03-10 21:41:48 +00:00
|
|
|
#include <LibGUI/Application.h>
|
2020-08-19 13:29:43 +00:00
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
#include <LibGUI/Calendar.h>
|
|
|
|
#include <LibGUI/Icon.h>
|
2020-03-10 21:41:48 +00:00
|
|
|
#include <LibGUI/Menu.h>
|
2021-04-13 14:18:20 +00:00
|
|
|
#include <LibGUI/Menubar.h>
|
2023-06-29 01:17:31 +00:00
|
|
|
#include <LibGUI/Painter.h>
|
2022-07-17 21:29:44 +00:00
|
|
|
#include <LibGUI/Process.h>
|
2021-04-13 14:18:20 +00:00
|
|
|
#include <LibGUI/Toolbar.h>
|
2020-03-10 21:41:48 +00:00
|
|
|
#include <LibGUI/Window.h>
|
2023-06-29 01:17:31 +00:00
|
|
|
#include <LibGfx/Font/FontDatabase.h>
|
|
|
|
#include <LibGfx/Palette.h>
|
2022-01-04 17:14:56 +00:00
|
|
|
#include <LibMain/Main.h>
|
2020-03-10 21:41:48 +00:00
|
|
|
|
2022-01-04 17:14:56 +00:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2020-03-10 21:41:48 +00:00
|
|
|
{
|
2023-06-29 01:17:31 +00:00
|
|
|
TRY(Core::System::pledge("stdio recvfd sendfd rpath wpath cpath proc exec unix"));
|
2020-03-10 21:41:48 +00:00
|
|
|
|
2023-05-05 04:24:53 +00:00
|
|
|
auto app = TRY(GUI::Application::create(arguments));
|
2020-03-10 21:41:48 +00:00
|
|
|
|
2023-06-29 01:17:31 +00:00
|
|
|
StringView filename;
|
|
|
|
|
|
|
|
Core::ArgsParser args_parser;
|
|
|
|
args_parser.add_positional_argument(filename, "File to read from", "file", Core::ArgsParser::Required::No);
|
|
|
|
|
|
|
|
args_parser.parse(arguments);
|
|
|
|
|
|
|
|
if (!filename.is_empty()) {
|
|
|
|
if (!FileSystem::exists(filename) || FileSystem::is_directory(filename)) {
|
|
|
|
warnln("File does not exist or is a directory: {}", filename);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-15 23:33:39 +00:00
|
|
|
Config::pledge_domain("Calendar");
|
2022-09-19 19:23:40 +00:00
|
|
|
Config::monitor_domain("Calendar");
|
2022-07-15 23:33:39 +00:00
|
|
|
|
2023-06-29 01:17:31 +00:00
|
|
|
TRY(Core::System::pledge("stdio recvfd sendfd rpath wpath cpath proc exec unix"));
|
2022-01-20 17:27:56 +00:00
|
|
|
TRY(Core::System::unveil("/etc/timezone", "r"));
|
2022-01-04 17:14:56 +00:00
|
|
|
TRY(Core::System::unveil("/res", "r"));
|
2022-07-17 21:29:44 +00:00
|
|
|
TRY(Core::System::unveil("/bin/CalendarSettings", "x"));
|
2023-06-29 01:17:31 +00:00
|
|
|
TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw"));
|
2023-12-25 17:56:19 +00:00
|
|
|
TRY(Core::System::unveil("/tmp/session/%sid/portal/launch", "rw"));
|
2022-01-04 17:14:56 +00:00
|
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
2020-03-10 21:41:48 +00:00
|
|
|
|
2022-07-11 17:32:29 +00:00
|
|
|
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-calendar"sv));
|
2023-09-16 11:51:33 +00:00
|
|
|
auto window = GUI::Window::construct();
|
2020-03-10 21:41:48 +00:00
|
|
|
window->set_title("Calendar");
|
2023-09-21 16:05:11 +00:00
|
|
|
window->restore_size_and_position("Calendar"sv, "Window"sv, { { 600, 480 } });
|
|
|
|
window->save_size_and_position_on_close("Calendar"sv, "Window"sv);
|
2020-08-19 13:29:43 +00:00
|
|
|
window->set_icon(app_icon.bitmap_for_size(16));
|
2020-03-10 21:41:48 +00:00
|
|
|
|
2023-06-29 01:17:31 +00:00
|
|
|
auto calendar_widget = TRY(Calendar::CalendarWidget::create(window));
|
|
|
|
window->set_main_widget(calendar_widget);
|
2020-08-19 13:29:43 +00:00
|
|
|
|
2023-11-17 20:04:40 +00:00
|
|
|
window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
|
|
|
|
if (calendar_widget->request_close())
|
|
|
|
return GUI::Window::CloseRequestDecision::Close;
|
|
|
|
return GUI::Window::CloseRequestDecision::StayOpen;
|
|
|
|
};
|
|
|
|
|
2023-06-29 01:17:31 +00:00
|
|
|
window->show();
|
2021-03-30 00:43:40 +00:00
|
|
|
|
2023-06-29 01:17:31 +00:00
|
|
|
if (!filename.is_empty()) {
|
|
|
|
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, filename);
|
|
|
|
if (!response.is_error()) {
|
|
|
|
calendar_widget->load_file(response.release_value());
|
|
|
|
}
|
|
|
|
}
|
2020-08-18 15:08:54 +00:00
|
|
|
|
2020-07-04 12:05:19 +00:00
|
|
|
app->exec();
|
2022-01-04 17:14:56 +00:00
|
|
|
|
|
|
|
return 0;
|
2020-03-10 21:41:48 +00:00
|
|
|
}
|