2020-08-23 00:55:16 -03:00
|
|
|
/*
|
2022-02-09 20:00:13 -03:00
|
|
|
* Copyright (c) 2020-2022, the SerenityOS developers.
|
2020-08-23 00:55:16 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-23 00:55:16 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-10-30 23:29:38 -03:00
|
|
|
#include "HelpWindow.h"
|
2022-01-11 08:26:04 -03:00
|
|
|
#include "LibFileSystemAccessClient/Client.h"
|
2020-08-23 00:55:16 -03:00
|
|
|
#include "Spreadsheet.h"
|
|
|
|
|
#include "SpreadsheetWidget.h"
|
2020-11-07 16:48:41 -03:00
|
|
|
#include <AK/ScopeGuard.h>
|
2022-02-09 20:00:13 -03:00
|
|
|
#include <AK/Try.h>
|
2020-08-23 00:55:16 -03:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2020-08-24 17:23:22 -03:00
|
|
|
#include <LibCore/File.h>
|
2022-02-09 20:00:13 -03:00
|
|
|
#include <LibCore/System.h>
|
2020-08-23 00:55:16 -03:00
|
|
|
#include <LibGUI/Application.h>
|
2020-11-02 13:51:07 -03:00
|
|
|
#include <LibGUI/Clipboard.h>
|
2020-08-24 14:08:45 -03:00
|
|
|
#include <LibGUI/FilePicker.h>
|
2020-11-02 16:30:17 -03:00
|
|
|
#include <LibGUI/Icon.h>
|
2020-08-24 14:08:45 -03:00
|
|
|
#include <LibGUI/Menu.h>
|
2021-04-13 11:18:20 -03:00
|
|
|
#include <LibGUI/Menubar.h>
|
2021-03-22 10:02:21 -03:00
|
|
|
#include <LibGUI/MessageBox.h>
|
2020-08-23 00:55:16 -03:00
|
|
|
#include <LibGUI/Window.h>
|
2022-02-09 20:00:13 -03:00
|
|
|
#include <LibMain/Main.h>
|
2021-03-12 13:29:37 -03:00
|
|
|
#include <unistd.h>
|
2020-08-23 00:55:16 -03:00
|
|
|
|
2022-02-09 20:00:13 -03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2020-08-23 00:55:16 -03:00
|
|
|
{
|
2022-04-03 20:13:41 -03:00
|
|
|
TRY(Core::System::pledge("stdio recvfd sendfd rpath fattr unix cpath wpath thread"));
|
2020-11-02 18:34:29 -03:00
|
|
|
|
2022-04-16 13:17:39 -03:00
|
|
|
auto app = TRY(GUI::Application::try_create(arguments));
|
2020-11-02 18:34:29 -03:00
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
char const* filename = nullptr;
|
2020-08-24 17:23:22 -03:00
|
|
|
|
2020-08-23 00:55:16 -03:00
|
|
|
Core::ArgsParser args_parser;
|
2020-08-24 17:23:22 -03:00
|
|
|
args_parser.add_positional_argument(filename, "File to read from", "file", Core::ArgsParser::Required::No);
|
|
|
|
|
|
2022-02-09 20:00:13 -03:00
|
|
|
args_parser.parse(arguments);
|
2020-08-23 00:55:16 -03:00
|
|
|
|
2020-08-24 17:23:22 -03:00
|
|
|
if (filename) {
|
|
|
|
|
if (!Core::File::exists(filename) || Core::File::is_directory(filename)) {
|
2020-10-06 10:02:05 -03:00
|
|
|
warnln("File does not exist or is a directory: {}", filename);
|
2020-08-24 17:23:22 -03:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-24 10:12:04 -03:00
|
|
|
TRY(Core::System::unveil("/tmp/user/%uid/portal/webcontent", "rw"));
|
2021-03-20 07:30:49 -03:00
|
|
|
// For writing temporary files when exporting.
|
2022-02-09 20:00:13 -03:00
|
|
|
TRY(Core::System::unveil("/tmp", "crw"));
|
|
|
|
|
TRY(Core::System::unveil("/etc", "r"));
|
2022-07-11 14:32:29 -03:00
|
|
|
TRY(Core::System::unveil(Core::StandardPaths::home_directory(), "rwc"sv));
|
2022-02-09 20:00:13 -03:00
|
|
|
TRY(Core::System::unveil("/res", "r"));
|
|
|
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
2020-08-23 00:55:16 -03:00
|
|
|
|
2022-07-11 14:32:29 -03:00
|
|
|
auto app_icon = GUI::Icon::default_icon("app-spreadsheet"sv);
|
2020-08-23 00:55:16 -03:00
|
|
|
auto window = GUI::Window::construct();
|
|
|
|
|
window->resize(640, 480);
|
2020-11-02 16:30:17 -03:00
|
|
|
window->set_icon(app_icon.bitmap_for_size(16));
|
2020-08-23 00:55:16 -03:00
|
|
|
|
2022-01-11 08:26:04 -03:00
|
|
|
auto& spreadsheet_widget = window->set_main_widget<Spreadsheet::SpreadsheetWidget>(*window, NonnullRefPtrVector<Spreadsheet::Sheet> {}, filename == nullptr);
|
2020-08-24 14:08:45 -03:00
|
|
|
|
2021-09-30 22:31:35 -03:00
|
|
|
spreadsheet_widget.initialize_menubar(*window);
|
2022-02-26 13:32:54 -03:00
|
|
|
spreadsheet_widget.update_window_title();
|
2021-02-26 09:12:08 -03:00
|
|
|
|
|
|
|
|
window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
|
|
|
|
|
if (spreadsheet_widget.request_close())
|
|
|
|
|
return GUI::Window::CloseRequestDecision::Close;
|
|
|
|
|
return GUI::Window::CloseRequestDecision::StayOpen;
|
|
|
|
|
};
|
2020-08-24 14:08:45 -03:00
|
|
|
|
2020-08-23 00:55:16 -03:00
|
|
|
window->show();
|
|
|
|
|
|
2022-01-11 08:26:04 -03:00
|
|
|
if (filename) {
|
2022-05-22 06:13:46 -03:00
|
|
|
auto file = TRY(FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, filename));
|
|
|
|
|
spreadsheet_widget.load_file(file);
|
2022-01-11 08:26:04 -03:00
|
|
|
}
|
|
|
|
|
|
2020-08-23 00:55:16 -03:00
|
|
|
return app->exec();
|
|
|
|
|
}
|