2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-02-15 00:29:06 +03:00
|
|
|
#include <AK/ByteBuffer.h>
|
2020-02-06 17:04:03 +03:00
|
|
|
#include <LibCore/File.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/AboutDialog.h>
|
|
|
|
#include <LibGUI/Action.h>
|
|
|
|
#include <LibGUI/Application.h>
|
|
|
|
#include <LibGUI/Menu.h>
|
|
|
|
#include <LibGUI/MenuBar.h>
|
|
|
|
#include <LibGUI/Window.h>
|
2020-05-28 19:21:22 +03:00
|
|
|
#include <LibWeb/PageView.h>
|
2019-06-15 21:20:55 +03:00
|
|
|
#include <stdio.h>
|
2019-06-15 19:55:47 +03:00
|
|
|
|
2019-06-15 21:20:55 +03:00
|
|
|
int main(int argc, char** argv)
|
2019-06-15 19:55:47 +03:00
|
|
|
{
|
2020-02-02 17:07:41 +03:00
|
|
|
GUI::Application app(argc, argv);
|
2019-09-25 12:44:22 +03:00
|
|
|
|
2020-02-02 14:34:39 +03:00
|
|
|
auto f = Core::File::construct();
|
2019-09-25 12:45:47 +03:00
|
|
|
bool success;
|
|
|
|
if (argc < 2) {
|
2020-02-02 14:34:39 +03:00
|
|
|
success = f->open(STDIN_FILENO, Core::IODevice::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescription::No);
|
2019-09-25 12:45:47 +03:00
|
|
|
} else {
|
|
|
|
f->set_filename(argv[1]);
|
2020-02-02 14:34:39 +03:00
|
|
|
success = f->open(Core::IODevice::OpenMode::ReadOnly);
|
2019-09-25 12:45:47 +03:00
|
|
|
}
|
|
|
|
if (!success) {
|
2019-09-21 21:50:06 +03:00
|
|
|
fprintf(stderr, "Error: %s\n", f->error_string());
|
2019-06-15 21:20:55 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2019-06-21 21:54:13 +03:00
|
|
|
|
2020-06-21 23:04:26 +03:00
|
|
|
auto html = f->read_all();
|
2019-06-16 22:35:03 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
auto window = GUI::Window::construct();
|
2020-05-28 19:21:22 +03:00
|
|
|
auto& widget = window->set_main_widget<Web::PageView>();
|
2020-06-21 23:04:26 +03:00
|
|
|
widget.load_html(html, URL());
|
2020-03-04 11:46:23 +03:00
|
|
|
if (!widget.document()->title().is_null())
|
|
|
|
window->set_title(String::format("%s - HTML", widget.document()->title().characters()));
|
2019-09-29 17:26:28 +03:00
|
|
|
else
|
|
|
|
window->set_title("HTML");
|
2019-09-25 12:44:22 +03:00
|
|
|
window->show();
|
|
|
|
|
2020-04-21 17:01:00 +03:00
|
|
|
auto menubar = GUI::MenuBar::construct();
|
2019-09-29 22:00:41 +03:00
|
|
|
|
2020-04-04 13:18:40 +03:00
|
|
|
auto& app_menu = menubar->add_menu("HTML");
|
|
|
|
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
|
2019-09-29 22:00:41 +03:00
|
|
|
app.quit();
|
|
|
|
}));
|
|
|
|
|
2020-04-04 13:18:40 +03:00
|
|
|
auto& help_menu = menubar->add_menu("Help");
|
|
|
|
help_menu.add_action(GUI::Action::create("About", [&](auto&) {
|
2020-02-06 13:56:38 +03:00
|
|
|
GUI::AboutDialog::show("HTML", Gfx::Bitmap::load_from_file("/res/icons/32x32/filetype-html.png"), window);
|
2019-09-29 22:00:41 +03:00
|
|
|
}));
|
|
|
|
|
|
|
|
app.set_menubar(move(menubar));
|
|
|
|
|
2020-02-06 13:56:38 +03:00
|
|
|
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"));
|
2019-09-29 22:00:41 +03:00
|
|
|
|
2019-09-25 12:44:22 +03:00
|
|
|
return app.exec();
|
2019-06-15 19:55:47 +03:00
|
|
|
}
|