From da2de8932c26b51a5a521a1c0a92c6e005c4e135 Mon Sep 17 00:00:00 2001 From: Poommetee Ketson Date: Wed, 5 Jul 2017 22:07:43 +0700 Subject: [PATCH] About: add thirdparty license info --- editor/SCsub | 149 +++++++++++++++++++++++++++++++++++++++-- editor/editor_node.cpp | 102 +++++++++++++++++++++++++--- editor/editor_node.h | 5 ++ 3 files changed, 243 insertions(+), 13 deletions(-) diff --git a/editor/SCsub b/editor/SCsub index 47bdec2e0d9..f0d378c097b 100644 --- a/editor/SCsub +++ b/editor/SCsub @@ -187,9 +187,11 @@ def make_authors_header(target, source, env): def make_license_header(target, source, env): - src = source[0].srcnode().abspath + src_copyright = source[0].srcnode().abspath + src_license = source[1].srcnode().abspath dst = target[0].srcnode().abspath - f = open(src, "rb") + f = open(src_license, "rb") + fc = open(src_copyright, "rb") g = open(dst, "wb") g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") @@ -201,6 +203,145 @@ def make_license_header(target, source, env): g.write("\n\t\"" + line.strip().replace("\"", "\\\"") + "\\n\"") g.write(";\n") + + tp_current = 0 + tp_file = "" + tp_comment = "" + tp_copyright = "" + tp_license = "" + + tp_licensename = "" + tp_licensebody = "" + + tp = [] + tp_licensetext = [] + for line in fc: + if line.startswith("#"): + continue + + if line.startswith("Files:"): + tp_file = line[6:].strip() + tp_current = 1 + elif line.startswith("Comment:"): + tp_comment = line[8:].strip() + tp_current = 2 + elif line.startswith("Copyright:"): + tp_copyright = line[10:].strip() + tp_current = 3 + elif line.startswith("License:"): + if tp_current != 0: + tp_license = line[8:].strip() + tp_current = 4 + else: + tp_licensename = line[8:].strip() + tp_current = 5 + elif line.startswith(" "): + if tp_current == 1: + tp_file += "\n" + line.strip() + elif tp_current == 3: + tp_copyright += "\n" + line.strip() + elif tp_current == 5: + if line.strip() == ".": + tp_licensebody += "\n" + else: + tp_licensebody += line[1:] + else: + if tp_current != 0: + if tp_current == 5: + tp_licensetext.append([tp_licensename, tp_licensebody]) + + tp_licensename = "" + tp_licensebody = "" + else: + added = False + for i in tp: + if i[0] == tp_comment: + i[1].append([tp_file, tp_copyright, tp_license]) + added = True + break + if not added: + tp.append([tp_comment,[[tp_file, tp_copyright, tp_license]]]) + + tp_file = [] + tp_comment = "" + tp_copyright = [] + tp_license = "" + tp_current = 0 + + about_thirdparty = "" + about_tp_copyright_count = "" + about_tp_license = "" + about_tp_copyright = "" + about_tp_file = "" + + for i in tp: + about_thirdparty += "\t\"" + i[0] + "\",\n" + about_tp_copyright_count += str(len(i[1])) + ", " + for j in i[1]: + file_body = "" + copyright_body = "" + for k in j[0].split("\n"): + if file_body != "": + file_body += "\\n\"\n" + file_body += "\t\"" + k.strip().replace("\"", "\\\"") + for k in j[1].split("\n"): + if copyright_body != "": + copyright_body += "\\n\"\n" + copyright_body += "\t\"" + k.strip().replace("\"", "\\\"") + + about_tp_file += "\t" + file_body + "\",\n" + about_tp_copyright += "\t" + copyright_body + "\",\n" + about_tp_license += "\t\"" + j[2] + "\",\n" + + about_license_name = "" + about_license_body = "" + + for i in tp_licensetext: + body = "" + for j in i[1].split("\n"): + if body != "": + body += "\\n\"\n" + body += "\t\"" + j.strip().replace("\"", "\\\"") + + about_license_name += "\t\"" + i[0] + "\",\n" + about_license_body += "\t" + body + "\",\n" + + g.write("static const char *about_thirdparty[] = {\n") + g.write(about_thirdparty) + g.write("\t0\n") + g.write("};\n") + g.write("#define THIRDPARTY_COUNT " + str(len(tp)) + "\n") + + g.write("static const int about_tp_copyright_count[] = {\n\t") + g.write(about_tp_copyright_count) + g.write("0\n};\n") + + g.write("static const char *about_tp_file[] = {\n") + g.write(about_tp_file) + g.write("\t0\n") + g.write("};\n") + + g.write("static const char *about_tp_copyright[] = {\n") + g.write(about_tp_copyright) + g.write("\t0\n") + g.write("};\n") + + g.write("static const char *about_tp_license[] = {\n") + g.write(about_tp_license) + g.write("\t0\n") + g.write("};\n") + + g.write("static const char *about_license_name[] = {\n") + g.write(about_license_name) + g.write("\t0\n") + g.write("};\n") + g.write("#define LICENSE_COUNT " + str(len(tp_licensetext)) + "\n") + + g.write("static const char *about_license_body[] = {\n") + g.write(about_license_body) + g.write("\t0\n") + g.write("};\n") + g.write("#endif\n") if (env["tools"] == "yes"): @@ -254,8 +395,8 @@ if (env["tools"] == "yes"): env.Command('#editor/authors.gen.h', "../AUTHORS.md", make_authors_header) # License - env.Depends('#editor/license.gen.h', "../LICENSE.txt") - env.Command('#editor/license.gen.h', "../LICENSE.txt", make_license_header) + env.Depends('#editor/license.gen.h', ["../COPYRIGHT.txt", "../LICENSE.txt"]) + env.Command('#editor/license.gen.h', ["../COPYRIGHT.txt", "../LICENSE.txt"], make_license_header) env.add_source_files(env.editor_sources, "*.cpp") diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index c52a133e78b..1df991ab246 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4948,6 +4948,13 @@ void EditorNode::_check_gui_base_size() { } } +void EditorNode::_license_tree_selected() { + + TreeItem *selected = _tpl_tree->get_selected(); + _tpl_text->select(0, 0, 0, 0); + _tpl_text->set_text(selected->get_metadata(0)); +} + void EditorNode::open_export_template_manager() { export_template_manager->popup_manager(); @@ -5037,6 +5044,8 @@ void EditorNode::_bind_methods() { ClassDB::bind_method(D_METHOD("_dim_timeout"), &EditorNode::_dim_timeout); ClassDB::bind_method(D_METHOD("_check_gui_base_size"), &EditorNode::_check_gui_base_size); + ClassDB::bind_method(D_METHOD("_license_tree_selected"), &EditorNode::_license_tree_selected); + ADD_SIGNAL(MethodInfo("play_pressed")); ADD_SIGNAL(MethodInfo("pause_pressed")); ADD_SIGNAL(MethodInfo("stop_pressed")); @@ -6110,15 +6119,6 @@ EditorNode::EditorNode() { dev_base->set_v_size_flags(Control::SIZE_EXPAND); tc->add_child(dev_base); - TextEdit *license = memnew(TextEdit); - license->set_name(TTR("License")); - license->set_h_size_flags(Control::SIZE_EXPAND_FILL); - license->set_v_size_flags(Control::SIZE_EXPAND_FILL); - license->set_wrap(true); - license->set_readonly(true); - license->set_text(String::utf8(about_license)); - tc->add_child(license); - VBoxContainer *dev_vbc = memnew(VBoxContainer); dev_vbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); dev_base->add_child(dev_vbc); @@ -6151,6 +6151,90 @@ EditorNode::EditorNode() { hs->set_modulate(Color(0, 0, 0, 0)); dev_vbc->add_child(hs); } + + TextEdit *license = memnew(TextEdit); + license->set_name(TTR("License")); + license->set_h_size_flags(Control::SIZE_EXPAND_FILL); + license->set_v_size_flags(Control::SIZE_EXPAND_FILL); + license->set_wrap(true); + license->set_readonly(true); + license->set_text(String::utf8(about_license)); + tc->add_child(license); + + VBoxContainer *license_thirdparty = memnew(VBoxContainer); + license_thirdparty->set_name(TTR("Thirdparty License")); + license_thirdparty->set_h_size_flags(Control::SIZE_EXPAND_FILL); + tc->add_child(license_thirdparty); + + Label *tpl_label = memnew(Label); + tpl_label->set_custom_minimum_size(Size2(0, 64 * EDSCALE)); + tpl_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + tpl_label->set_autowrap(true); + tpl_label->set_text(TTR("Godot Engine relies on a number of thirdparty free and open source libraries, all compatible with the terms of its MIT license. The following is an exhaustive list of all such thirdparty components with their respective copyright statements and license terms.")); + license_thirdparty->add_child(tpl_label); + + HSplitContainer *tpl_hbc = memnew(HSplitContainer); + tpl_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); + tpl_hbc->set_v_size_flags(Control::SIZE_EXPAND_FILL); + tpl_hbc->set_split_offset(240 * EDSCALE); + license_thirdparty->add_child(tpl_hbc); + + _tpl_tree = memnew(Tree); + _tpl_tree->set_hide_root(true); + TreeItem *root = _tpl_tree->create_item(); + TreeItem *tpl_ti_all = _tpl_tree->create_item(root); + tpl_ti_all->set_text(0, TTR("All Components")); + TreeItem *tpl_ti_tp = _tpl_tree->create_item(root); + tpl_ti_tp->set_text(0, TTR("Components")); + tpl_ti_tp->set_selectable(0, false); + TreeItem *tpl_ti_lc = _tpl_tree->create_item(root); + tpl_ti_lc->set_text(0, TTR("Licenses")); + tpl_ti_lc->set_selectable(0, false); + int read_idx = 0; + String long_text = ""; + for (int i = 0; i < THIRDPARTY_COUNT; i++) { + + TreeItem *ti = _tpl_tree->create_item(tpl_ti_tp); + String thirdparty = String(about_thirdparty[i]); + ti->set_text(0, thirdparty); + String text = thirdparty + "\n"; + long_text += "- " + thirdparty + "\n\n"; + for (int j = 0; j < about_tp_copyright_count[i]; j++) { + + text += "\n Files:\n " + String(about_tp_file[read_idx]).replace("\n", "\n ") + "\n"; + String copyright = String::utf8(" \u00A9 ") + String::utf8(about_tp_copyright[read_idx]).replace("\n", String::utf8("\n \u00A9 ")); + text += copyright; + long_text += copyright; + String license = "\n License: " + String(about_tp_license[read_idx]) + "\n"; + text += license; + long_text += license + "\n"; + read_idx++; + } + ti->set_metadata(0, text); + } + for (int i = 0; i < LICENSE_COUNT; i++) { + + TreeItem *ti = _tpl_tree->create_item(tpl_ti_lc); + String licensename = String(about_license_name[i]); + ti->set_text(0, licensename); + long_text += "- " + licensename + "\n\n"; + String licensebody = String(about_license_body[i]); + ti->set_metadata(0, licensebody); + long_text += " " + licensebody.replace("\n", "\n ") + "\n\n"; + } + tpl_ti_all->set_metadata(0, long_text); + tpl_hbc->add_child(_tpl_tree); + + _tpl_text = memnew(TextEdit); + _tpl_text->set_h_size_flags(Control::SIZE_EXPAND_FILL); + _tpl_text->set_v_size_flags(Control::SIZE_EXPAND_FILL); + _tpl_text->set_wrap(true); + _tpl_text->set_readonly(true); + tpl_hbc->add_child(_tpl_text); + + _tpl_tree->connect("item_selected", this, "_license_tree_selected"); + tpl_ti_all->select(0); + _tpl_text->set_text(tpl_ti_all->get_metadata(0)); } warning = memnew(AcceptDialog); diff --git a/editor/editor_node.h b/editor/editor_node.h index 24acedbf269..49ac04243c4 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -431,6 +431,9 @@ private: List previous_scenes; bool opening_prev; + Tree *_tpl_tree; + TextEdit *_tpl_text; + void _dialog_action(String p_file); void _edit_current(); @@ -636,6 +639,8 @@ private: void _dim_timeout(); void _check_gui_base_size(); + void _license_tree_selected(); + protected: void _notification(int p_what); static void _bind_methods();